简体   繁体   中英

What is Powershell's equivalent to Pythons sys.stdin.read()?

We are using Splunk on Windows and in the latest version we now need to migrate our scripted alerts to custom alerts. Long story short, the new framework does not longer use positional arguments but payload (stdin). If using Python it is simple, as shown in Spunk documentation

settings = json.loads(sys.stdin.read())

I have not been able to figure out how I can do the same using Powershell. The cmdlet read-host only reads stdin from the keyboard. I have also found examples of using the cmdlet get-content to read from stdin, but I have only found examples when using an exsisting file

Get-Content c:\scripts\test.txt

It might be that I need to do something related to what is described in this accepted answer .

$psi = New-Object System.Diagnostics.ProcessStartInfo;
....
....

But I do not want to send to stdin of another process, I want to read what another process has sent to "my" process, the Powershell-script.

使用自动变量 $input

$settings = $input | Out-String | ConvertFrom-Json

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM