PowerShell Packaged to exe; Trouble with Write-Output

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 4 years and 9 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
jbake2019
Posts: 4
Last visit: Fri Feb 26, 2021 10:41 am

PowerShell Packaged to exe; Trouble with Write-Output

Post 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?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post by jvierra »

You have to use the correct host to get output. "V5 Host (command line)".
jbake2019
Posts: 4
Last visit: Fri Feb 26, 2021 10:41 am

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

Post by jbake2019 »

Tried v5 command line, still no output though.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post by jvierra »

Is this a form? Is it a simple script? What commands are you trying to output?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post 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
jbake2019
Posts: 4
Last visit: Fri Feb 26, 2021 10:41 am

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

Post 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.
jbake2019
Posts: 4
Last visit: Fri Feb 26, 2021 10:41 am

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

Post 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.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post 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.
This topic is 4 years and 9 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked