Issue with executing a command in parallel

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
SIMMS7400
Posts: 546
Joined: 07 Jan 2016 07:47

Issue with executing a command in parallel

#1 Post by SIMMS7400 » 16 Jan 2021 04:58

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?

T3RRY
Posts: 250
Joined: 06 May 2020 10:14

Re: Issue with executing a command in parallel

#2 Post by T3RRY » 16 Jan 2021 07:08

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

jfl
Posts: 226
Joined: 26 Oct 2012 06:40
Location: Saint Hilaire du Touvet, France
Contact:

Re: Issue with executing a command in parallel

#3 Post by jfl » 18 Jan 2021 02:22

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

Post Reply