svobol13
svobol13

Reputation: 1960

Powershell write to stdout (no newline)

I need something absolutely simple but apparently totaly impossible. I need to write something to stdout in powershell.

So far I found only write-output but this unfortunately appends linefeed. I tried to somehow "hack" it by getting stdout from .net but I always get host stream which doesnt do what I want.

Do anyone knows a way how can I write for example 1 to stdout so when I pipe the script exactly 1 is on stdin of other script? I accept any kind of hack but I dont want to do redirection on invocation like ()sth>&1 | script.

Upvotes: 1

Views: 5105

Answers (1)

Aspergillus
Aspergillus

Reputation: 31

I was going crazy trying to capture PowerShell output from a PowerShell command I executed from within a Python script. And it did not work because PowerShell does not properly write to STDOUT.

But I found some ways...

First is using the PowerShell command Write-Information:

Write-Information -Message "This goes to Stdout" -InformationAction Continue

The other is starting PowerShell with cmd and capture the output of cmd:

cmd.exe /C "powershell.exe -command "Write-Host 'This goes to Stdout'"

Upvotes: 3

Related Questions