2

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.

3
  • 1
    Just call your batch with a &. Example: & "c:\yourbatch.bat" Commented Sep 3, 2015 at 7:33
  • @jisaak: And how I set different working directory? Commented Sep 3, 2015 at 7:58
  • 1
    You could read the current location using get-location, store that in a variable, change the working dir, call the script and finally set the previous location back. For example: $wd = Get-Location; Set-Location "you working dir"; & "Your batch"; Set-Location $wd Commented Sep 3, 2015 at 8:02

1 Answer 1

2

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).

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.