加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

如何在我的Perl脚本中调用shell命令?

发布时间:2020-12-15 21:21:30 所属栏目:大数据 来源:网络整理
导读:任何人都可以给我一个例子,说明如何调用shell命令,在Perl脚本中说’ls -a’,以及检索命令输出的方式。 解决方法 How to run a shell script from a Perl program 1. Using system system($command,@arguments); For example: system("sh","script.sh","--
任何人都可以给我一个例子,说明如何调用shell命令,在Perl脚本中说’ls -a’,以及检索命令输出的方式。

解决方法

How to run a shell script from a Perl program

1. Using system system($command,@arguments);

For example:

system("sh","script.sh","--help" );

system("sh script.sh --help");

System will execute the $command with
@arguments and return to your script when finished. You may check $!
for certain errors passed to the OS by the external application. Read
the documentation for system for the nuances of how various
invocations are slightly different.

2. Using exec

This is very similar to the use of 07001,but it will
terminate your script upon execution. Again,read the documentation
for 07002 for more.

3. Using backticks or qx//

my $output = `script.sh --option`;

my $output = qx/script.sh --option/;

The backtick operator and it’s equivalent qx// excute the command and options inside the operator and
return that commands output to STDOUT when it finishes.

There are also ways to run external applications through creative use of 07003,but this is advanced use; read the documentation for more.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读