PowerShell Packaged to exe; Trouble with Write-Output

Ask your Windows 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.
Locked
jbake2019
Posts: 4
Joined: Fri Jun 21, 2019 7:55 pm

PowerShell Packaged to exe; Trouble with Write-Output

Post by jbake2019 » Fri Jun 21, 2019 1:06 pm

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?

User avatar
jvierra
Posts: 13718
Joined: Tue May 22, 2007 9:57 am
Contact:

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

Post by jvierra » Fri Jun 21, 2019 2:28 pm

You have to use the correct host to get output. "V5 Host (command line)".

jbake2019
Posts: 4
Joined: Fri Jun 21, 2019 7:55 pm

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

Post by jbake2019 » Mon Jun 24, 2019 7:20 am

Tried v5 command line, still no output though.

User avatar
jvierra
Posts: 13718
Joined: Tue May 22, 2007 9:57 am
Contact:

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

Post by jvierra » Mon Jun 24, 2019 7:52 am

Is this a form? Is it a simple script? What commands are you trying to output?

User avatar
jvierra
Posts: 13718
Joined: Tue May 22, 2007 9:57 am
Contact:

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

Post by jvierra » Mon Jun 24, 2019 7:55 am

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
Joined: Fri Jun 21, 2019 7:55 pm

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

Post by jbake2019 » Mon Jun 24, 2019 9:01 am

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
Joined: Fri Jun 21, 2019 7:55 pm

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

Post by jbake2019 » Mon Jun 24, 2019 9:30 am

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.

User avatar
jvierra
Posts: 13718
Joined: Tue May 22, 2007 9:57 am
Contact:

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

Post by jvierra » Mon Jun 24, 2019 10:45 am

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.

Locked