标准输入到 powershell 脚本 [英] Stdin to powershell script

查看:61
本文介绍了标准输入到 powershell 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个正在运行的服务,它可以调用外部进程来修改文本流,然后再将其返回给该服务.文本流从服务传递到 stdout 上的外部进程,并从 stdin 上的服务读取修改后的结果.换句话说,外部进程(命令)可以用作文本过滤器".我想使用 powershell 脚本来修改文本流.我可以使用命令powershell -executionpolicy bypass -noninteractive ./myscript.ps1"在 win 2008r2 上从服务成功启动脚本.

I have a service running that can invoke an external process to modify a text stream before it is returned to the service. The text stream is handed from the service to the external process on stdout and the modified result is read from the service on stdin. The external process (command) can in other words be used as a text "filter". I would like to use a powershell script to modify the text stream. I can successfully launch a script from the service on win 2008r2 using the command "powershell -executionpolicy bypass -noninteractive ./myscript.ps1".

我可以使用 write-host cmdlet 使脚本将文本返回到 stdout 上的服务.我的问题是我找不到一种方法来读取脚本中 stdin 上的文本.读取主机似乎不起作用,因为它需要交互式 shell.

I can make the script return text to the service on stdout using the write-host cmdlet. My problem is that I can't find a way to read the text on stdin in the script. Read-host doesn't seem to work as it requires an interactive shell.

我想避免将服务的标准输出写入 tmp 文件并在脚本中读取该文件,因为该服务是多线程的(一次可以启动多个外部命令)和 tmp 文件管理(锁定、唯一文件名等)是不需要的.

I would like to avoid writing the stdout from the service to a tmp file and read that file in the script as the service is multithreaded (can launch more than one external command at a time) and tmp file management (locking, unique filenames etc) is not desired.

这是可能的还是我应该为此使用例如 Perl?Powershell 看起来很有吸引力,因为它预装在我所有的 win 2008 机器上.

Is this possible or should I use for example Perl for this? Powershell seems compelling as it is preinstalled on all my win 2008 machines.

推荐答案

只是猜测 - 我会看看 [Console]::In |gm -static.

Just a guess - I would have a look at [Console]::In | gm -static.

这篇关于标准输入到 powershell 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆