-
-
Save gbrayut/7207751 to your computer and use it in GitHub Desktop.
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
using Call in a cmd file is where I was running into issues.
Say that process allowed you to pass
/?
as the argument.Give it a shot and it will ALWAYS output the help from
call
instead of passing the argument through to the process.