Page 1 of 1

PowerShell Packaged to exe; Trouble with Write-Output

Posted: Fri Jun 21, 2019 1:06 pm
by jbake2019
Hello all,

I'm delivering a packaged ps script (exe) to remote machines (software delivery application executing locally).

I can't seem to get the basic output to return to my delivery program console though.

It's a simple script in the package for this test:

Write-Host "Write-Host"
Write-Output "Write-Output"
Etc... for every Write-* option in PS.

Before packaging, Write-Output would return to my app console, but after packaging it's all blank.

I've tried package settings for PS V3 Silent & Command Line, but to no avail.

Any thoughts?

Re: PowerShell Packaged to exe; Trouble with Write-Output

Posted: Fri Jun 21, 2019 2:28 pm
by jvierra
You have to use the correct host to get output. "V5 Host (command line)".

Re: PowerShell Packaged to exe; Trouble with Write-Output

Posted: Mon Jun 24, 2019 7:20 am
by jbake2019
Tried v5 command line, still no output though.

Re: PowerShell Packaged to exe; Trouble with Write-Output

Posted: Mon Jun 24, 2019 7:52 am
by jvierra
Is this a form? Is it a simple script? What commands are you trying to output?

Re: PowerShell Packaged to exe; Trouble with Write-Output

Posted: Mon Jun 24, 2019 7:55 am
by jvierra
Put the following in a PS1 file and build with V5 (command line) and you will see the output.

Code: Select all

Write-Host "Write-Host"
Write-Output "Write-Output"
pause

Re: PowerShell Packaged to exe; Trouble with Write-Output

Posted: Mon Jun 24, 2019 9:01 am
by jbake2019
Maybe you missed it in my op, but I’m delivering with a software delivery program. I am able to get output from write-output and write-host if I send it as a ps1, but if sending an exec of it I get nothing back.

My test script is a simple one just to try to get output back to the software delivery programs console.

So not sure why output is not returning from the ps1 thru the exe back to the software delivery application console.

Re: PowerShell Packaged to exe; Trouble with Write-Output

Posted: Mon Jun 24, 2019 9:30 am
by jbake2019
Figured it out.

Was using {cmd/c start ps1.exe} which was spawning a new console and not preserving the output.

Now I used {cmd /c call ps1.exe} and it returned just fine.

So CALL vs START... (facepalm)

Thanks anyways for the assist.

Re: PowerShell Packaged to exe; Trouble with Write-Output

Posted: Mon Jun 24, 2019 10:45 am
by jvierra
You don't need any of that, Just execute the exe.
cmd /c ps1.exe

The same as any other exe that you run. There is also no need to use CMD. Just run the EXE. Use START when you want to execute the exe in anew process. Use CLL to call an external CMD/BAT file.

The best advice is to never use CMD as it is obsolete and will likely be removed in the next version of Windows. In Windows 10 and later PowerShell is the default console for Windows and CMD exists only for backwards compatibility. No new work should ever rely on CMD/BAT/CMD files.