Created
October 29, 2013 01:25
-
-
Save anonymous/7207747 to your computer and use it in GitHub Desktop.
Example of a .cmd file passing an argument to a .ps1 file and getting the error code back.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
powershell -file c:\temp\script.ps1 -test:%1 | |
echo %ERRORLEVEL% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Calling batch file with argument, which gets passed to the ps1 script | |
c:\Temp>batch.cmd asdf | |
//asdf came from %1 argument to batch.cmd | |
c:\Temp>powershell -file c:\temp\script.ps1 -test:asdf | |
asdf | |
//%ERRORLEVEL% has exit code from ps1 file | |
c:\Temp>echo 5 | |
5 | |
//Add this to the end of the batch.cmd if you want error code passed to calling processes | |
exit %ERRORLEVEL% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Param( | |
[string]$test | |
) | |
write-host $test | |
exit 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment