Prob executing Batch File (win server)

If you think that something doesn't work in Aware IM post your message here
Post Reply
Jaymer
Posts: 2430
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

Prob executing Batch File (win server)

Post by Jaymer »

here's a batch file PrepLoadNightly.bat, located in C:\DREFiles\
call C:\DREFiles\prep\PrepCG.bat
cd C:\DREFiles\incoming
del *.0
del *.1
call C:\DREFiles\incoming\Nav0.bat
powershell -File C:\DREFiles\incoming\Monitor_CG_Run_Once.ps1

In the Aware scheduler, if I do this:
IF DOMAIN()<>'CGDEMO' AND TESTING_MODE() = 'No' AND (CURRENT_TIME='23:27' AND CURRENT_DATE>=01/01/2005) then
EXECUTE PROGRAM 'C:\DREFiles\PrepLoadNightly.bat'

Then the bold line above, which does about 50 "curl" executions, will fail after 6-8 curls - it locks up somehow - a task has to be killed - "curl executable" locks an output file and also has to be terminated. strange stuff.

But if I manually launch the exact same batch file, it runs fine.
Its always run fine.
Only now finding this weird behavior when I'm trying to get Aware to tie all this stuff together.
Click Here to see a collection of my tips & hacks on this forum. Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
hpl123
Posts: 2579
Joined: Fri Feb 01, 2013 1:13 pm
Location: Scandinavia

Re: Prob executing Batch File (win server)

Post by hpl123 »

SOMETHING in the back of my mind tells me running some bat files from Aware caused problems for me but I can´t for the life of me remember what it was :(. It may have been the contents of the actual bat file, i.e what it does, or something like that as I do run bat files from Aware on a regular basis without issues.

In some scenarios I use an AutoIT exe (compile script to exe) to run bat files and might be an solution: https://www.autoitscript.com/site/

Example Autotit script to run bat:

Code: Select all

Run("c:\path\example.bat")
Henrik (V8 Developer Ed. - Windows)
Jaymer
Posts: 2430
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

[SOLVED] Prob executing Batch File (win server)

Post by Jaymer »

Instead of calling a BAT file from Aware, I used EXECUTE PROGRAM to start a Powershell script.
I let it call the exact BAT file that was crapping out from AIM.
Same result.
(remember, if I manually run the BAT file it works fine)

Solved it by having the commands in the OP put into a PS1 script (with a few mods for PS syntax).
Got rid of the top level BAT file.
Inside, it still executes the same 2 BAT files as before.
All runs fine.

Scheduler rule:
IF DOMAIN()<>'CGDEMO' AND TESTING_MODE() = 'No' AND (CURRENT_TIME='22:50' AND CURRENT_DATE>=01/01/2005) then
Nightly_Process_Tenants
EXECUTE PROGRAM 'powershell -File C:\DREFiles\PS_StartNightly.ps1'

NOTE: FYI
-- nightly process starts
Aware runs thru Tenants, creating lines in a tmp database table.
An Aware Export sends those lines to a physical file... named "nightly.bat"
A prep.bat routine formats the files, removing quotes, commas, the 1st line inserted by the Export command
(each line is a curl.exe command to retrieve data)
Then, that file is executed, bringing lots of curl.exe results into a dir
After all that data is retrieved, a Powershell script starts:
Loops thru each file found
.Scrubs raw HTML into an importable format
.Imports it into a SQL table
Executes a MS SQL Stored Procedure to load/merge new data into Aware tables
-- nightly process finished
Click Here to see a collection of my tips & hacks on this forum. Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
Jaymer
Posts: 2430
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

Re: Prob executing Batch File (win server)

Post by Jaymer »

NOTE
I was getting a few records hanging around in EXECUTION CONTEXTS after running the nightly.

Turns out I didn't have an "exit" as the last line in my final PowerShell script.
Not the PS1 script called from Aware, but the PS1 script that IT was calling after some other processing.
That was hanging as an active Windows process, so it wasn't returning to Aware to end properly.
Called by Scheduler -> PS_StartNightly.ps1:

Code: Select all

Set-Location "C:\DREFiles\incoming"
Remove-Item C:\DREFiles\incoming\*

Start-Process -FilePath C:\DREFiles\prep\PrepCG.bat -Wait
Start-Process -FilePath  C:\DREFiles\Nav0.bat -Wait

Start-Process Powershell C:\DREFiles\lib\Monitor_CG_Run_Once.ps1 -RedirectStandardOutput C:\DREFiles\Nightly.log -Wait
Monitor_CG_Run_Once.ps1 needed the "exit" stmt
Click Here to see a collection of my tips & hacks on this forum. Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
Post Reply