title: Executing a bash script from a Perl program
body: <p>I'm trying to write a Perl program which will execute a bash script. The Perl script looks like this</p>
  
  <pre><code>#!/usr/bin/perl
  
  use diagnostics;
  use warnings;
  
  require 'userlib.pl';
  use CGI qw(:standard); 
  
  ReadParse();
  
  my $q = new CGI;
  my $dir = $q-&gt;param('X');
  my $s = $q-&gt;param('Y');
  
  ui_print_header(undef, $text{'edit_title'}.$dir, "");
  
  print  $dir."&lt;br&gt;";
  print  $s."&lt;br&gt;";
  print "Under Construction &lt;br&gt;";
  
  use Cwd;
  my $pwd = cwd();
  my $directory = "/Logs/".$dir."/logmanager/".$s;
  my $command = $pwd."/script ".$directory."/".$s.".tar";
  
  print $command."&lt;br&gt;";
  print $pwd."&lt;br&gt;";
  
  chdir($directory);
  my $pwd1 = cwd();
  print $pwd1."&lt;br&gt;";
  
  system($command, $directory) or die "Cannot open Dir: $!";
  </code></pre>
  
  <p>The script fail with the following error:</p>
  
  <hr>
  
  <pre><code>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.)        
  </code></pre>
  
  <hr>
  
  <p>I've checked that the permissions are correct, the tar file I'm passing to my bash script exists, and also tried from the command line to run the same command I'm trying to run from the Perl script ( <code>/usr/libexec/webmin/foobar/script /path/filename.tar</code> ) and it works properly.</p>