简体   繁体   English

将多个 STDIN 输入从 powershell 脚本传递到 perl 脚本

[英]Passing multiple STDIN inputs from powershell script into perl script

I have an existing perl script (which i cannot modify) which has two STDIN calls.我有一个现有的 perl 脚本(我无法修改),它有两个 STDIN 调用。 I would like to run this perl script from a powershell script and feed it the two "user inputs" but using variables.我想从 powershell 脚本运行这个 perl 脚本,并向它提供两个“用户输入”,但使用变量。

For a single input I tried对于我尝试的单个输入

'input' | '输入' | perl <file_path>.pl perl <文件路径>.pl

This correctly uses the 'input' as the first value of the STDIN call.这正确地使用“输入”作为 STDIN 调用的第一个值。 The issue is it only works once.问题是它只能工作一次。

How can I pass two sets of STDIN inputs via the powershell script?如何通过 powershell 脚本传递两组 STDIN 输入?

You are asking how to provide two lines to the STDIN of a program in PowerShell.您询问如何向 PowerShell 中的程序的 STDIN 提供两行。

You can use either of the following:您可以使用以下任一方法:

"line1", "line2" | perl ...
"line1`nline2`n" | perl ...

Demo:演示:

chomp( my $x = <STDIN> );
chomp( my $y = <STDIN> );
print( "<x:$x>\n" );
print( "<y:$y>\n" );
> "line1", "line2" | perl a.pl
<x:line1>
<y:line2>
> "line1`nline2`n" | perl a.pl
<x:line1>
<y:line2>

Note that a BOM gets added by PowerShell 5. No idea how to prevent that.请注意,BOM 由 PowerShell 5 添加。不知道如何防止这种情况发生。 This is not the case with newer versions of PowerShell.较新版本的 PowerShell 并非如此。

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

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