Power shell script to run a batch file:
start-Process C:\Test.bat |
Out-File C:\test.txt
when I check the text.txt
file is empty?
Power shell script to run a batch file:
start-Process C:\Test.bat |
Out-File C:\test.txt
when I check the text.txt
file is empty?
Don't use Start-Process
if all you need is to run a program in the more or less default way.
C:\Test.bat | Out-file C:\Test.txt
should work fine, although you most likely lack write privileges on C:\
so that's perhaps not the most useful path to use.
Start-Process
does not redirect standard output by default. You have to tell it to do so:
Start-Process -FilePath .\test.bat -NoNewWindow -Wait -RedirectStandardOutput ".\test.txt"
Note, that this will not capture errors. If you want them too, add -RedirectStandardError ".\test-stderr.txt"
. This must be a different file than the one that you used for -RedirectStandardOutput
.