by antonela at 2013-04-04 00:45:16
in a .cmd I use at the end:by nohandle at 2013-04-04 07:17:00
exit /B %ERRORCODE% (where ERRORCODE=%errorlevel%)
In this way I know how my .cmd finishes and I can use this variable for a traffic light in another program.
How could I write something similar in powershell?
I use $LastExitCode to test the errors…
exit /B $LastExitCode doesn’t function
I am not sure if you:by antonela at 2013-04-05 02:27:29
1) are trying to replace existing batch file with a powershell script while maintaining the same behavior
2) are trying to detect exit code of a batch file that was run from powershell srcipt
Which one is it?
the first one.by nohandle at 2013-04-05 02:58:20
In my file 1.ps1 I use
sqlcmd -S server -d dbase -b -Q "EXEC pr_MAIN_OLAP"
after this row I put
if ( $LastExitCode -ne 0) { write-host "error!"
exit $LastExitCode
}
exit $LastExitCode
If I run this file (powershell.exe 1.ps1) I’m not sure if using exit $LastExitCode it’s enough to have the exit code I need.
0 -OK
1- Error
What do you think?
If you are not sure try itby antonela at 2013-04-05 05:27:01
Save this in c:\temp\test.ps1 filesqlcmd give me error
exit $lastExitCode
and from the old command line run:powershell -file "c:\temp\test.ps1"
echo %errorlevel%
Do you get 1?
thank you very much