在Perl中运行Shell命令 [英] Run Shell command in Perl

查看:136
本文介绍了在Perl中运行Shell命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在Perl中运行一些Shell Linux命令(例如创建一个文件夹)。但我不能执行以下命令:

  echo'mypassword'| gpg --passphrase-fd 0 --output outfile --decrypt inputfile 

sh文件,并可以在Shell中执行。但是当我调用.sh文件时,Perl无法运行它。我使用 open3 系统打开命令运行。



< >解决方案

尝试使用backquote / backtick,似乎工作正常:

 #!/ usr / bin / perl 
use strict;

`echo'mypassword'| gpg --passphrase-fd 0 --output outfile --decrypt inputfile`

我最好使用一些cpan模块,例如 GPG


I can run some Shell Linux commands in Perl (for example create a folder). But I can't execute followed command:

echo 'mypassword' | gpg --passphrase-fd 0 --output outfile --decrypt inputfile

I add this command in .sh file and could execute in Shell fine. but when I call .sh file, Perl couldn't run it. I used open3, system, open commands to run. I could run other .sh file, but not for this command.

Can you help me please?

解决方案

Try using backquote/backtick, seems to work fine:

#!/usr/bin/perl
use strict;

`echo 'mypassword' | gpg --passphrase-fd 0 --output outfile --decrypt inputfile`

P.S. I would better use some cpan module like GPG.

这篇关于在Perl中运行Shell命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆