Tomas Kubes
Tomas Kubes

Reputation: 25098

How to call batch from powershell so I can see realtime output in powershell console

I need to call batch from powershell with specific working directory. I don't want new console to be opened, but I would like to see the output of the batch as a part of the output from powershell script.

I could forward the standard output to file and then write it by Write-Host, but the batch takes time and I would like to see the output in realtime as it is processing.

I tried Process-Start, but I don't know how to redirect standard output of batch to standard output of powershell.

Upvotes: 2

Views: 1118

Answers (1)

equinox93
equinox93

Reputation: 133

You can add 'cmd /c ' to your ps script, and to change directories, you can use @jisaak suggestion, so:

$wd = Get-Location;
Set-Location "batch file directory";
cmd /c "Your batch";
Set-Location $wd;

That will open a new cmd in the current console and all the output will be directed to it(when the batch will reach EOF the cmd terminates).

Upvotes: 2

Related Questions