CMD Command Line: One command plus direct output of the ERRORLEVEL into a TXT?
Moderator: DosItHelp
-
- Posts: 7
- Joined: 02 Feb 2017 01:19
CMD Command Line: One command plus direct output of the ERRORLEVEL into a TXT?
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
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
Re: CMD Command Line: One command plus direct output of the ERRORLEVEL into a TXT?
You could run a separate instance of cmd with delayed expansion enabled
It might be easier to use conditional command chaining though.
Steffen
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
-
- Posts: 7
- Joined: 02 Feb 2017 01:19
Re: CMD Command Line: One command plus direct output of the ERRORLEVEL into a TXT?
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.
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.
Re: CMD Command Line: One command plus direct output of the ERRORLEVEL into a TXT?
What about my first suggestion? (dir :* is only an example that generates errorlevel 1)
Steffen
Code: Select all
cmd /von /c "dir :*&>"file.txt" echo !errorlevel!"
Steffen
-
- Posts: 7
- Joined: 02 Feb 2017 01:19
Re: CMD Command Line: One command plus direct output of the ERRORLEVEL into a TXT?
Hello Steffen,
when I execute
cmd /von ""C:\Program Files\testapp\testapp.exe" &>"file.txt" echo !errorlevel!"
nothing happens.
when I execute
cmd /von ""C:\Program Files\testapp\testapp.exe" &>"file.txt" echo !errorlevel!"
nothing happens.
Re: CMD Command Line: One command plus direct output of the ERRORLEVEL into a TXT?
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.)
Steffen
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
-
- Posts: 7
- Joined: 02 Feb 2017 01:19
Re: CMD Command Line: One command plus direct output of the ERRORLEVEL into a TXT?
Hello Steffen,
it works! Many thanks!
Have a nice day!
TD
it works! Many thanks!
Have a nice day!
TD