Reading command line output from another batch script?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
script-newbie
Posts: 5
Joined: 20 Aug 2012 11:20

Reading command line output from another batch script?

#1 Post by script-newbie » 20 Aug 2012 11:30

Hey guys,

I am relatively new to DOS and Batch Scripting but I am attempting to make a Batch script file that does a rough time calculation based on a time (I.E. 08:24) from a third party program.

The way it works is I first execute a third party program called "CCExtractor". It begins writing progress to the stdErr output. I then want to execute my batch script to skim the command output from the CCExtractor process. I've seen a lot of people write the output to some type of text file but I do not think this is feasible in my case because I would continually have to reopen the file in my batch script and not sure if that would work since the CCExtractor program would continually be writing to it.

I have my batch script working by reading a txt file of the output CCExtractor gives but I am not sure how to have this run in conjunction with the CCExtractor ouput!

Any Ideas??

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Reading command line output from another batch script?

#2 Post by Ed Dyreen » 20 Aug 2012 11:47

'
Place your command/program inside a for loop

Code: Select all

@echo off

for /f "delims=" %%? in (

       'for /?'

) do   echo.%%?

pause
exit
Notice the smileys :)

script-newbie
Posts: 5
Joined: 20 Aug 2012 11:20

Re: Reading command line output from another batch script?

#3 Post by script-newbie » 20 Aug 2012 17:04

Thanks for the reply!

That worked. Is there a way to get the 'stdOut' output similar to the 'stdErr?'

Code: Select all

FOR /F "tokens=*" %%i in ('"ccextractorwin.exe --gui_mode_reports -out=srt -trim GP066367.mpg"') do (
   echo %%i
)


This doesn't seem to work! :oops:

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Reading command line output from another batch script?

#4 Post by Ed Dyreen » 20 Aug 2012 17:07

'
try

Code: Select all

FOR /F "tokens=*" %%i in ('"ccextractorwin.exe" --gui_mode_reports -out^=srt -trim GP066367.mpg') do (
   echo %%i
)
But first check if it works at all

Code: Select all

"ccextractorwin.exe" --gui_mode_reports -out=srt -trim GP066367.mpg

script-newbie
Posts: 5
Joined: 20 Aug 2012 11:20

Re: Reading command line output from another batch script?

#5 Post by script-newbie » 20 Aug 2012 17:27

Hey I tried this:

Code: Select all

FOR /F "tokens=*" %%i in ('"ccextractorwin.exe" --gui_mode_reports -trim GP066367.mpg -out=srt') do (
   echo sadsd %%i
)


It seems to work but for whatever reason it seems to think: out=srt is an input file.

It is trying to process "srt" as its own file. Is there a way to correctly supply the arguments?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Reading command line output from another batch script?

#6 Post by foxidrive » 20 Aug 2012 17:31

Does the program expect the last part of the command to be the input file?

IE: try the command from the prompt:

ccextractorwin.exe --gui_mode_reports -trim GP066367.mpg -out=srt

script-newbie
Posts: 5
Joined: 20 Aug 2012 11:20

Re: Reading command line output from another batch script?

#7 Post by script-newbie » 20 Aug 2012 17:35

This command does indeed work in the command prompt.

Code: Select all

ccextractorwin.exe --gui_mode_reports -trim GP05312.mpg -out=srt


It appears the = sign is causing problems.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Reading command line output from another batch script?

#8 Post by Squashman » 20 Aug 2012 17:40

script-newbie wrote:This command does indeed work in the command prompt.

Code: Select all

ccextractorwin.exe --gui_mode_reports -trim GP05312.mpg -out=srt


It appears the = sign is causing problems.

Shouldn't it be -o filename

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Reading command line output from another batch script?

#9 Post by foxidrive » 20 Aug 2012 18:29

script-newbie wrote:This command does indeed work in the command prompt.

Code: Select all

ccextractorwin.exe --gui_mode_reports -trim GP05312.mpg -out=srt


It appears the = sign is causing problems.



Try escaping the equals sign like this: ^=

or use "-out=srt" with the double quotes, if the program supports them.

script-newbie
Posts: 5
Joined: 20 Aug 2012 11:20

Re: Reading command line output from another batch script?

#10 Post by script-newbie » 22 Aug 2012 10:44

I really appreciate the help!

But I am not sure if this solution will work.

Code: Select all

FOR /F "tokens=*" %%i in ('"ccextractorwin.exe" --gui_mode_reports -out^=srt -trim GP066367.mpg -stdout -o GP066367.srt') do (
   echo TEST %%i
)


When this executes it outputs the CCExtractor output but I am unable to access it. In theory it should have "TEST" in front of each CCExtractor stdout output on the Command Window screen but this doesn't work.

It does print out my TEST output but not until the CCExtractor output is finished.

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Reading command line output from another batch script?

#11 Post by Ed Dyreen » 22 Aug 2012 11:16

script-newbie wrote:But I am not sure if this solution will work.

Code: Select all

FOR /F "tokens=*" %%i in ('"ccextractorwin.exe" --gui_mode_reports -out^=srt -trim GP066367.mpg -stdout -o GP066367.srt') do (
   echo TEST %%i
)

If it doesn't work then this is unrelated to the batch, which is syntactically correct ( all special characters are either quoted or escaped ). This doesn't mean you won't run into problems because of the way you chose to retrieve and handle the output.
script-newbie wrote:When this executes it outputs the CCExtractor output but I am unable to access it.
Sorry, das habe ich nicht verstehen was meinst du ?
script-newbie wrote:In theory it should have "TEST" in front of each CCExtractor stdout output on the Command Window screen but this doesn't work.
unless your version of cmd.EXE is broken, it works for everybody else.

Code: Select all

>for /f "tokens=1-2" %a in ( 'echo.line1A line1B ^&echo.line2A' ) do echo.TEST %a &echo.TEST %b

>echo.TEST line1A   & echo.TEST line1B
TEST line1A
TEST line1B

>echo.TEST line2A   & echo.TEST
TEST line2A
TEST

>
script-newbie wrote:It does print out my TEST output but not until the CCExtractor output is finished.
Yes, that is how 'for /?' works.

Post Reply