是否可以在perl中使用system()将输入通过“ <”传递到另一个脚本?

Is it possible to pipe input to another script with '<' using the system() in perl?

我看过几个类似的问题,但似乎都没有一个解决这个问题,或者它们使用了我不熟悉的管道形式,或者我使用"管道"代替了正确的词。

首先,我在Windows 7上,我想做的是让一个Perl脚本多次调用并输入到另一个Perl Script中。

我要执行此操作的方法是使用System()函数。

当直接放到命令行中时,虽然有些草率,但是可以使用:

1
Functionalscript.pl < InputFile > OutputFile

这将从输入文件中获取内容以执行该功能,并将其完美地写入输出文件。 但是,在我的调用脚本中使用" system()"函数时,输入未注册,但创建了输出文件(只是空白)。

问题在于:

1
system("Functionalscript.pl < InputFile > OutputFile")

出于某种原因,使用该功能脚本不会将输入作为stdin接收。 有没有办法使这项工作?


1
system("x:/path/perl.exe Functionalscript.pl InputFile > OutputFile")

由mpapec提供,Works。 必须包含" x:/path/perl.exe"。


根据perldoc -f system(http://perldoc.perl.org/functions/system.html):

If there is only one scalar argument, the argument is checked for shell metacharacters, and if there are any, the entire argument is passed to the system's command shell for parsing (this is /bin/sh -c on Unix platforms, but varies on other platforms). If there are no shell metacharacters in the argument, it is split into words and passed directly to execvp , which is more efficient.

这意味着如果命令中包含><,则应将其传递到外壳程序,并且输入和输出重定向应按预期进行。