Page 1 of 1

Issue with executing a command in parallel

Posted: 16 Jan 2021 04:58
by SIMMS7400
Hi Folks -

I have the following command that executes an Oracle utility:

Code: Select all

CALL C:\path\to\util\utility.bat operation Param1 Param2 Param3 Param4 Param5 Param6  && (
	ECHO Successful : Execute Data Load Rule
	) || (
	ECHO Failed : Execute Data Load Rule
)
The utility is java based. What it does is while executing, it creates a log file in the same directory as where the script is executed from and spools lots of information to the log as it processes, some of which I want to capture. The challenge is if the command executes with success, the log is automatically deleted by the utility. If the command fails, the log is not deleted which is good because then I have another process to parse the log.

So basically what I need to do is run the command above and then then somehow copy the log to a temp to preserve it. I don't need to continue to copy the log to temp as it processes as the pertinent information I need is from the first few lines of the log anyway.

I assume I can't use call, right? The challenge with START is that it will proceed with the rest of the script. Any ideas?

Re: Issue with executing a command in parallel

Posted: 16 Jan 2021 07:08
by T3RRY
Try Start /B to initialise the script in parellel
and test delay length required to catch the existance of the output file
An example Pair [you may need to adjust the delay method]

Caller.bat

Code: Select all

@Echo OFF & CD %~dp0 & mode 1000
Del "newoutput.txt" 2> nul
Start /B callee.bat
Echo started
Call :Delay 2> nul
Call :Delay 2> nul
Call :Delay 2> nul
Call :Delay 2> nul
Call :Delay 2> nul
Call :Delay 2> nul
Call :Delay 2> nul
Call :Delay 2> nul
Call :Delay 2> nul
Call :Delay 2> nul
For /L %%n in () Do (
 If exist "output.txt" (Copy "output.txt" "newoutput.txt" > nul 2> nul )Else (
  Timeout /T 1
  TYPE "newoutput.txt" 2> nul
  Exit /B
 )
)
Callee.bat

Code: Select all

@Echo off & CD "%~dp0"
For /L %%n in (1 1 50)Do >>"output.txt" Echo/Item %%n
Del output.txt
Exit /B

Re: Issue with executing a command in parallel

Posted: 18 Jan 2021 02:22
by jfl
You should use a Win32 port of the Unix tail utility. It's designed precisely to do what you want to do.
There's one coming with git for Windows, if you have it. Typically in "C:\Program Files\Git\usr\bin\tail.exe".
Else you can find a tail.exe in old win32 ports like UnxUtils or GnuWin32.

Then the tail options -f and --pid will allow you to capture and filter what you want in that log file, waiting for the background application to complete.

1) Start your utility.bat.
2) Identify its PID and the LOGFILE name.
3) Run:

Code: Select all

tail -f --pid=PID LOGFILE >PERSISTENT_COPY
Or if you're just interested in one keyword, you can filter the tail output. Ex:

Code: Select all

tail -f --pid=PID LOGFILE | findstr KEYWORD