标准输入到 powershell 脚本
我正在运行一个服务,它可以调用外部进程来修改文本流,然后再将其返回到服务。文本流从服务传递到 stdout 上的外部进程,并从 stdin 上的服务读取修改后的结果。换句话说,外部过程(命令)可以用作文本“过滤器”。我想使用 powershell 脚本来修改文本流。我可以使用命令“powershell -executionpolicy绕过-noninteractive ./myscript.ps1”在win 2008r2上成功从服务启动脚本。
我可以使用 write-host cmdlet 让脚本将文本返回到标准输出上的服务。我的问题是我找不到读取脚本中 stdin 上的文本的方法。读取主机似乎不起作用,因为它需要交互式 shell。
我想避免将服务中的标准输出写入 tmp 文件并在脚本中读取该文件,因为该服务是多线程的(一次可以启动多个外部命令)和 tmp 文件管理(锁定、唯一文件名等)是不希望的。
这是可能的还是我应该使用例如 Perl 来实现这一点? Powershell 似乎很引人注目,因为它预装在我所有的 win 2008 机器上。
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".
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.
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.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只是一个猜测 - 我会看看
[Console]::In | gm -静态
。Just a guess - I would have a look at
[Console]::In | gm -static
.