[ILUG] Perl Question.
kor at compsoc.com
Wed Jun 8 12:40:38 IST 2005
> > If I change the system line in the script (below) and paste the single
> > line output to the shell all works fine.
> What do you mean exactly ? Does the perl script not actually run the
> script /root/grab\-config for you?
> Well, you're escaping too much ... the first thing to figure
> out is if the expect script is actually getting called at all. the next
> thing to look at is how you've split up the arguments to system ...
from the perldoc page for system():
system PROGRAM LIST
... If there is more than one argument in LIST, or if LIST is an
array with more than one value, starts the program given by the
first element of the list with arguments given by the rest of
the list. If there is only one scalar argument, the argument is
checked for shell metacharacters, and if there are any, the
entire argument is passed to the system’s command shell ...
You've passed a list to system() so the first argument,
"/root/grab\-config ", is executed directly, with subsequent arguments
to system() being passed to tht program (or expect script, whatever).
The shell doesn't get a chance to parse the argument.
The backslash in the argument doesn't seem to upset perl, but the
trailing space does - remove that and see if your problems are solved.
As Niall pointed out, you could probably join the arguments together as
a single string before calling system() with that single argument. Then
the shell would get to parse the line, and would probably get it right.
Personally I'd try to avoid the shell though, unless you specifically
want it to parse the line.
More information about the ILUG