I have an existing perl script (which i cannot modify) which has two STDIN calls. I would like to run this perl script from a powershell script and feed it the two "user inputs" but using variables.
For a single input I tried
'input' | perl <file_path>.pl
This correctly uses the 'input' as the first value of the STDIN call. The issue is it only works once.
How can I pass two sets of STDIN inputs via the powershell script?
CodePudding user response:
You are asking how to provide two lines to the STDIN of a program in PowerShell.
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. This is not the case with newer versions of PowerShell.