#pipe not working

17 messages · Page 1 of 1 (latest)

hasty verge
#

With the following command, I can retrieve the output in the temp file :
Start-Process powershell -Verb runAs -ArgumentList "C:\Users\Florian\Documents\Test\script.ps1 -Install *> $Env:TEMP\temp_python_output.txt"

But not with this one :
Start-Process powershell -Verb runAs -ArgumentList "C:\Users\Florian\Documents\Test\script.ps1 -Install | Out-File -FilePath $Env:TEMP\temp_python_output.txt"

plush flower
#

right, that's expected. are you asking why?

hasty verge
#
tiny hawk
#

What does script.ps1 contain?

#

| won't capture error output

hasty verge
#

The script runs correctly, but I can't get its output with Out-File

tiny hawk
#

Looks like the script is printing directly to screen with Write-Host or similar

#

That also won't be picked up by the pipeline

hasty verge
#

Thanks, I thought it would work

#

I guess that i'll use *> instead if pipes

tiny hawk
#

FWIW you don't need to escape \ in PowerShell-native contexts , it's just -FilePath $env:TEMP\temp_python_output.txt

#

You can also invoke powershell inline if you don't mind it blocking the thread, Start-Process isn't necessary:

powershell.exe -File C:\Users\Florian\Documents\Test\script.ps1 *> $env:TEMP\temp_python_output.txt
hasty verge
#

I use start process to run an administrator powershell because python initially executes command in a cmd. The full command is

powershell -Command "Start-Process powershell -Verb runAs -ArgumentList ..."

vital gate
#

because python initially executes command in a cmd
Are you doing multiple layers of indirection mainly because you don't want to see a visible window when you call python?
If yes, there's probably better options