简体   繁体   English

Powershell与Python的sys.stdin.read()等价的是什么?

[英]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. 我们正在Windows上使用Splunk,并且在最新版本中,我们现在需要将脚本化警报迁移到自定义警报。 Long story short, the new framework does not longer use positional arguments but payload (stdin). 简而言之,新框架不再使用位置参数,而是使用有效负载(stdin)。 If using Python it is simple, as shown in Spunk documentation 如果使用Python,这很简单,如Spunk文档中所示

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

I have not been able to figure out how I can do the same using Powershell. 我无法弄清楚如何使用Powershell进行相同的操作。 The cmdlet read-host only reads stdin from the keyboard. cmdlet读取主机仅从键盘读取stdin。 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 我还找到了使用cmdlet get-content从stdin读取的示例,但是我仅在使用现有文件时找到了示例

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. 但是我不想发送到另一个进程的stdin,我想阅读另一个进程发送给“我的”进程的Powershell脚本。

使用自动变量 $input

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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