0

I have a powershell script that runs an .exe tool.

& tool.exe

If I run the script from a cmd console, the exe output is not written through the cmd console...

C:\>powershell .\script.ps1

Insead, if I run the script from a Powershell console everything is alright.

Do you know how to make the exe output visible from the cmd console?

3
  • Why are you using, cmd.exe to run PowerShell - which starts the consolehost to run a .ps1 file to call an exe that needs cmd.exe? Use it directly to run your .exe. Anything you do in cmd.exe you can do directly in the consolehost. BTW, I just tested what you have here with a few .exes, and it works without the need for Write-*. So, it seems your exe is the root cause. Output to the screen is the PowerShell default. Write-Host should be avoided, unless you need to use color, or other very specific screen formatting needs. Use Out-Host, or Write-Output instead, if you have to use something. Commented May 6, 2019 at 22:32
  • I didn't know the difference between Write-host and Write-Output. Now it's clear for me, thanks. About the ps script, is a complex script that do many things, among others, run a .exe. In my case, the problem is that the exe output appears in the virtual ps console that is opened when I use "powershell" command in the cmd.exe, but it's is not brought to the cmd console. Commented May 7, 2019 at 8:59
  • For exe, cmd.exe gets called, thus a new PowerShell session. Output redirection is defined here: About Redirection : learn.microsoft.com/en-us/powershell/module/… --- stackoverflow.com/questions/19220933/… --- mnaoumov.wordpress.com/2015/01/11/… --- social.technet.microsoft.com/wiki/contents/articles/… Commented May 7, 2019 at 21:23

1 Answer 1

1

I think I resolved like this:

& tool.exe | Write-Host

It's not very smart, but it works...

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.