如何将参数从一个Perl脚本传递到另一个

如何将参数从一个Perl脚本传递到另一个

本文介绍了如何将参数从一个Perl脚本传递到另一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个脚本,我运行它和它运行后它有一些信息,我需要传递到下一个脚本运行。

I have a script which I run and after it's run it has some information that I need to pass to the next script to run.

Unix / DOS命令如下所示:

The Unix/DOS commands are like so:

perl -x -s param_send.pl
perl -x -s param_receive.pl

param_send.pl是:

param_send.pl is:

# Send param

my $send_var = "This is a variable in param_send.pl...\n";
$ARGV[0] = $send_var;
print "Argument: $ARGV[0]\n";

param_receive.pl is: p>

param_receive.pl is:

# Receive param

my $receive_var = $ARGV[0];
print "Parameter received: $receive_var";

但不打印任何内容。我知道我做错了,但从教程我不知道如何传递一个参数从一个脚本到下一个!

But nothing is printed. I know I am doing it wrong but from the tutorials I can't figure out how to pass a paramter from one script to the next!

非常感谢。 / p>

Many thanks in advance.

推荐答案

您可以在命令行上使用管道字符将stdout从第一个程序连接到第二个程序的stdin,然后可以写入(使用打印)或从(使用<> 运算符)读取。 >

You can use a pipe character on the command line to connect stdout from the first program to stdin on the second program, which you can then write to (using print) or read from (using the <> operator).

perl param_send.pl | perl param_receive.pl

如果希望第一个命令的输出是第二个命令的参数,你可以使用xargs:

If you want the output of the first command to be the arguments to the second command, you can use xargs:

perl param_send.pl | xargs perl param_receive.pl

这篇关于如何将参数从一个Perl脚本传递到另一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 20:20