Run Shell command in Perl

好久不见. 提交于 2020-01-06 02:21:09

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/16164179/run-shell-command-in-perl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!