Pass arguments through pipe to external command with system one after another
I am trying to open a external command from Perl using system call. I am working on Windows. How can I pass arguments to it one after another?
For example:
system("ex1.exe","arg1",arg2",....);
Here ex1.exe
is external command and i would like it to process arg1 first and then arg2 and so on.开发者_如何学运维..
I would appreciate for your reply,
Use a pipe open:
use strict;
use warnings;
{
local ++$|;
open my $EX1_PIPE, '|-', 'ex1.exe'
or die $!;
print $EX1_PIPE "$_\n"
for qw/arg1 arg2 arg3/;
close $EX1_PIPE or die $!;
}
I'm assuming you want to pipe data to ex1.exe
's STDIN; for example, if ex1.exe
is the following perl script:
print while <>;
Then if you run the above code your output should be:
arg1
arg2
arg3
Are you trying to execute ex1.exe once for each argument? Something similar to:
> ex1.exe arg1 > ex1.exe arg2 > ex1.exe arg3
If so, you would do:
for my $arg (@args)
{
system( 'ex1.exe', $arg);
}
精彩评论