【发布时间】:2015-07-08 06:52:37
【问题描述】:
我正在尝试编写一个执行 bash 脚本的 Perl 程序。 Perl 脚本如下所示
#!/usr/bin/perl
use diagnostics;
use warnings;
require 'userlib.pl';
use CGI qw(:standard);
ReadParse();
my $q = new CGI;
my $dir = $q->param('X');
my $s = $q->param('Y');
ui_print_header(undef, $text{'edit_title'}.$dir, "");
print $dir."<br>";
print $s."<br>";
print "Under Construction <br>";
use Cwd;
my $pwd = cwd();
my $directory = "/Logs/".$dir."/logmanager/".$s;
my $command = $pwd."/script ".$directory."/".$s.".tar";
print $command."<br>";
print $pwd."<br>";
chdir($directory);
my $pwd1 = cwd();
print $pwd1."<br>";
system($command, $directory) or die "Cannot open Dir: $!";
脚本失败并出现以下错误:
Can't exec "/usr/libexec/webmin/foobar/script
/path/filename.tar": No such file or directory at /usr/libexec/webmin/foobar/program.cgi line 23 (#3)
(W exec) A system(), exec(), or piped open call could not execute the
named program for the indicated reason. Typical reasons include: the
permissions were wrong on the file, the file wasn't found in
$ENV{PATH}, the executable in question was compiled for another
architecture, or the #! line in a script points to an interpreter that
can't be run for similar reasons. (Or maybe your system doesn't support #! at all.)
我检查了权限是否正确,我传递给我的 bash 脚本的 tar 文件存在,并且还尝试从命令行运行我尝试从 Perl 脚本运行的相同命令(@ 987654323@ ) 并且它工作正常。
【问题讨论】:
-
你写过你已经检查了权限,但只是为了澄清一下:执行
/usr/libexec/webmin/foobar/script的用户是否也有执行权限?您是否也检查了有关 shebang (#!) 的建议?例如,如果脚本以#!/bin/bash开头,则检查/bin/bash是否存在且可执行。 -
检查了这一切,正如我所说,如果我从命令行运行相同的工作正常
-
请在系统调用前加上
-f or die qq{File "$_" doesn't exist} for $command, $directory;并报告结果