DosTips.com

A Forum all about DOS Batch
It is currently 26 Sep 2017 13:53

All times are UTC-06:00




Post new topic  Reply to topic  [ 8 posts ] 
Author Message
PostPosted: 02 Feb 2017 02:04 
Offline

Joined: 02 Feb 2017 01:19
Posts: 7
CMD Command Line:
One CMD command, one command row, no BAT file. Is there a chance to get the ERRORLEVEL directly written in a TXT file?

I tried but I failed.

I don't want to create and save a BAT file each time.

I would prefer the simpler way: CMD single command plus export of the ERRORLEVEL in a TXT file, all in one command line.

TD :D


Top
   
PostPosted: 02 Feb 2017 03:06 
Offline
Expert

Joined: 22 Jan 2010 18:01
Posts: 2904
Location: Germany
You could run a separate instance of cmd with delayed expansion enabled
Code: Select all
cmd /von "dir :*&echo !errorlevel!"


It might be easier to use conditional command chaining though.
Code: Select all
dir :* && (echo errorlevel is 0) || (echo errorlevel other than 0)


Steffen


Top
   
PostPosted: 02 Feb 2017 03:17 
Offline

Joined: 02 Feb 2017 01:19
Posts: 7
Hi Steffen,

I need something like this:

( commandToExecute ) & echo %errorlevel%>"file.txt"

I want the error level integer value (0 or 2 or 5 or something else) get written in the txt file. Only that value.


Top
   
PostPosted: 02 Feb 2017 03:20 
Offline
Expert

Joined: 22 Jan 2010 18:01
Posts: 2904
Location: Germany
What about my first suggestion? (dir :* is only an example that generates errorlevel 1)
Code: Select all
cmd /von /c "dir :*&>"file.txt" echo !errorlevel!"


Steffen


Top
   
PostPosted: 02 Feb 2017 03:28 
Offline

Joined: 02 Feb 2017 01:19
Posts: 7
Hello Steffen,

when I execute

cmd /von ""C:\Program Files\testapp\testapp.exe" &>"file.txt" echo !errorlevel!"

nothing happens.


Top
   
PostPosted: 02 Feb 2017 03:35 
Offline
Expert

Joined: 22 Jan 2010 18:01
Posts: 2904
Location: Germany
The /c switch was missing (I already corrected the line above).
If this doesn't help use CALL to run the program. (Sometimes pathes in quotes won't execute.)

Code: Select all
cmd /von /c "call "C:\Program Files\testapp\testapp.exe"&>"file.txt" echo !errorlevel!"


Steffen


Top
   
PostPosted: 02 Feb 2017 04:15 
Offline

Joined: 02 Feb 2017 01:19
Posts: 7
Hello Steffen,

it works! Many thanks! :D

Have a nice day!

TD


Top
   
PostPosted: 02 Feb 2017 04:18 
Offline
Expert

Joined: 22 Jan 2010 18:01
Posts: 2904
Location: Germany
Thats good news :)


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 8 posts ] 

All times are UTC-06:00


Who is online

Users browsing this forum: No registered users and 12 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited