Skip to content

Instantly share code, notes, and snippets.

@gbrayut
Forked from anonymous/batch.cmd
Created October 29, 2013 01:26
Show Gist options
  • Save gbrayut/7207751 to your computer and use it in GitHub Desktop.
Save gbrayut/7207751 to your computer and use it in GitHub Desktop.
powershell -file c:\temp\script.ps1 -test:%1
echo %ERRORLEVEL%
//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%
Param(
[string]$test
)
write-host $test
exit 5
@ferventcoder
Copy link

using Call in a cmd file is where I was running into issues.

call "someprocess" %*

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment