1

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?

Manuel Batsching
  • 3,406
  • 14
  • 20
Spertrun
  • 11
  • 3
  • [Joey's solution](https://stackoverflow.com/a/60580096/45375) is effective; for background information, see [the linked duplicate](https://stackoverflow.com/a/60308095/45375) – mklement0 Mar 07 '20 at 18:11

2 Answers2

2

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.

Joey
  • 344,408
  • 85
  • 689
  • 683
0

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.

Manuel Batsching
  • 3,406
  • 14
  • 20