I have a command

$output = `somecommand parm1 parm2`;

When I try to run this perl script I get.

Can't exec "somecommand" at .....

It seems it is not seeing anything past the first space in between the `` I have a friend who runs this in a different env and it runs fine.

What could I have in my env that would cause this? I am using perl 5.20.0 .

  • 1
    You tried putting a full path in front of the command? What does "which somecommand" show on the commandline? – Tom Newton Jun 23 '15 at 19:24

It might be a PATH issue? Here is an example script that runs the echo command which is in my $PATH.

root@kt-wim-play:~# cat test.pl
#!/usr/bin/perl -w
use strict;

print "PATH=$ENV{PATH}\n";

print "Running a command... [" . `echo foo bar baz` . "]\n";

root@kt-wim-play:~# perl test.pl
Running a command... [foo bar baz
| improve this answer | |

If you are trying to run a linux command inside perl? Try this.

my $output = system("/path/to/command args");


| improve this answer | |
  • system() and backticks operate differently: The former gives you the numeric return code of the command, the latter gives you the output of the command). Presumably if the OP is using backticks (or qx//) they're doing so because they're more interested in the output thank the return code. – voretaq7 Jun 25 '15 at 17:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.