?
Solved

Get outout info from dos command

Posted on 2012-09-20
11
Medium Priority
?
639 Views
Last Modified: 2012-10-16
I'm running a dos script which runs an exe and passes in several parameters like so:

export.exe outputvideo camera1 file1

Open in new window


The out put on the dos command window is

Export Success or
Error video found!!


I need to know when it fails to retrieve video so I can log it.

How am I able to detect that the output is e.g. "Error video found"??

I have tried printing out the ERRORLEVEL but it is always 0.

Thanks
0
Comment
Question by:Wanting2LearnMan
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 29

Assisted Solution

by:Bill Bach
Bill Bach earned 1004 total points
ID: 38417926
It is a poor application that doesn't set ERRORLEVEL.  

You can easily fix this with:
export.exe outputvideo camera1 file1 | FIND "Success"

Now, %ErrorLevel% will be set to 0 if "Success" is on the output line, or 1 if it is not.
0
 

Author Comment

by:Wanting2LearnMan
ID: 38418062
Thanks BillBach,

I have tested it and find that it's not finding a string that I want.
For example when I run the exe like so:
cbe.exe export-video %1 %time1% %time2% %2.ps
echo errorLevel: %ERRORLEVEL%

Open in new window

and it runs successfully the following is output:
export-video CAM:8 FROM:2012-09-20:15:11:27 TO:2012-09-20:15:11:28 FILE:10SecsAg
o.ps
Connected to IP:192.168.1.13 on Port:22609
Login Successful
0 of 140
1 of 140
2 of 140
3 of 140
4 of 140
5 of 140
6 of 140
7 of 140
8 of 140
9 of 140
10 of 140
11 of 140
12 of 140
14 of 140
15 of 140
16 of 140
17 of 140
18 of 140
19 of 140
20 of 140
21 of 140
22 of 140
23 of 140
24 of 140
25 of 140
26 of 140
27 of 140
28 of 140
errorLevel: 0

Open in new window




But when I run it again this time looking for "Login Succesful" (as a test)

cbe.exe export-video %1 %time1% %time2% %2.ps | FIND "Login Successful"
echo errorLevel: %ERRORLEVEL%

Open in new window


The following is the output:

Login Successful
errorLevel: 0

Open in new window


Do you know why the | FIND isn't working???

Thanks
0
 
LVL 29

Assisted Solution

by:Bill Bach
Bill Bach earned 1004 total points
ID: 38418112
Ah, but the FIND *IS* working.  As I said, ERRORLEVEL will be 0 if the string is found.  (0 means "successful execution" to most applications.)

If that string were not found by FIND, then FIND would report ERRORLEVEL of 1.
0
Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

 
LVL 29

Assisted Solution

by:Bill Bach
Bill Bach earned 1004 total points
ID: 38418117
If you ALSO need the log file details, then you'll need two steps:

cbe.exe export-video %1 %time1% %time2% %2.ps >>LOGFILE.TXT
FIND "Login Successful" LOGFILE.TXT
echo errorLevel: %ERRORLEVEL%
0
 

Author Comment

by:Wanting2LearnMan
ID: 38418135
Thanks I'll get to it,

So why is the following text not displayed when I use the | FIND??

0 of 140
1 of 140
2 of 140
3 of 140
4 of 140
5 of 140
6 of 140
7 of 140
8 of 140
9 of 140
10 of 140
11 of 140
12 of 140
14 of 140
15 of 140
16 of 140
17 of 140
18 of 140
19 of 140
20 of 140
21 of 140
22 of 140
23 of 140
24 of 140
25 of 140
26 of 140
27 of 140
28 of 140

Open in new window


Thanks
0
 
LVL 60

Assisted Solution

by:Bill Prew
Bill Prew earned 500 total points
ID: 38418207
Where does CBE.EXE come from, is it something I can download and try?

Also, give the following construct a try, it can usually be a way to trap and react to success or failure of an EXE.

The && block inside the parens will only execute if the EXE succeeded, while the || block will execute if it fails.

cbe.exe export-video %1 %time1% %time2% %2.ps && (
    echo Success
) || (
    echo Failure
)

Open in new window

~bp
0
 
LVL 29

Assisted Solution

by:Bill Bach
Bill Bach earned 1004 total points
ID: 38418210
You don't see those lines because the FIND command looks in a data stream for the indicated text, and it FINDs the requested text.  If you want to display ALL lines, then you can include the /V option.  

Run the command FIND /? for other options used by this tool.
0
 

Author Comment

by:Wanting2LearnMan
ID: 38418491
re: Where does CBE.EXE come from, is it something I can download and try?
This is an internal exe that uses our own libraries so I'm sorry I cannot upload it.

Thanks
0
 
LVL 10

Assisted Solution

by:ReneGe
ReneGe earned 248 total points
ID: 38427372
I have a crazy idea here.

Could that possibly work?

export.exe outputvideo camera1 file1 | FINDSTR -i success && (ECHO ALL GOOD) || (ECHO IT DID NOT WORK)

Open in new window


Cheers,
Rene
0
 
LVL 60

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 38427401
Did you try my suggestion in http:#a38418207?

~bp
0
 
LVL 2

Assisted Solution

by:erobby
erobby earned 248 total points
ID: 38452505
Errorlevels only work on the last executed command.  If you look at your output you have several commands being completed and your errorlevel on line 33 is only reporting the results of line 32.

Your script is doing a loop and each part of the loop has it's own errorlevel associated with the execution of it's command.  By the time you get to the end of the process the errorlevel for any command that was executed prior is lost.

The program doesn't output errorlevels because that is a function of the OS, while some applications do have special error messages associated with then the DOS errorlevel is still available, but once again it's only for the last command executed and that value is 0 or higher with 0 being successful and anything else meaning an error has occurred.

If you are trying to get a accurate reading of success and failure you may consider using a "For" statement to do a loop through your data file instead of executing the loop within the the program.  That may be a little tricky because one of the variables is a date range.

As long as you use a "find" to search for the words success or failure it will always end in error.  Now BillBach was going along the right path with creating a log file of your output and doing a search of that file, but that will only show that you connected to the target and not your actual success or failure rate.

you have to take into consideration the following

Command being executed from Script:  [b]export-video CAM:8 FROM:2012-09-20:15:11:27 TO:2012-09-20:15:11:28 FILE:10SecsAgo.ps[/b]

First Command:  [b]Connected to IP:192.168.1.13 on Port:22609[/b]

Results of the command for the OS's Errorlevel value of 0 or 1:  [b]Login Successful[/b]

Once the connection is made it process the rest of the data

processing First value:  [b]0 of 140[/b]
This process will have it's own errorlevel of 0 or 1

processing Second value:  [b]1 of 140[/b]
This process will have it's own errorlevel of 0 or 1

And so on until it has finished process all the data, but each will have it's own errorlevel
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
This article will show, step by step, how to integrate R code into a R Sweave document
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question