Reputation: 7853
I want to execute a batch(*.bat
) file from Powershell. Is there any reason not to use option 1 below?
& path-to-batch-file
cmd.exe /c path-to-batch-file
Upvotes: 0
Views: 485
Reputation: 2890
I can only think of corner cases...
Option 1 probably uses the default file handler for .bat files. If that handler is changed, corrupted, or different than expected, a problem could arise. Though, this seems pretty unlikely.
Option 2 gives you the power to pass additional parameters to cmd.exe
, which might be valuable.
Option 2 might be slightly faster, but it's only a guess: in Option 1 powershell might need to lookup the shell handler for batch files from the registry first, then execute those instructions, whereas Option 2 needs only find the cmd.exe
executable and run it with supplied parameters.
Upvotes: 2