1

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 .

peterh
  • 4,953
  • 13
  • 30
  • 44
  • 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

2 Answers2

2

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
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Running a command... [foo bar baz
]
Wim Kerkhoff
  • 901
  • 1
  • 5
  • 12
0

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

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

http://www.perlmonks.org/?node_id=78523

chrisw9808
  • 309
  • 1
  • 5
  • `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