I have a powershell 2 script that I'm trying to develop. The purpose of this script is to wrap around a batch script and intelligently choose what version of said batch script to run. Somewhere along the lines in my code I have some logic that goes like this:
& $myCommand $args
$myCommand is the fully qualified filename of the batch file I want to run. $args is the args passed into this script. This works except it opens up a command window when running $myCommand. How do I prevent this so that the output is within the same powershell shell?
What's odd is that if I execute the command directly, it shows up the way I want it. So something like:
C:\myCommand.bat $args
Given that I need to choose which command I want to run at runtime, how do I make it so the output is in the same shell when I use the '&' to execute the command in the variable? Thanks!
Use Start-Process
with the -NoNewWindow
parameter instead of &
:
Start-Process -filepath C:\myCommand.bat -argumentList @("arg1","arg2") -NoNewWindow
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With