system() bites us

mako132 on 2003-02-07T17:36:40

Talk about having to read between the lines.

Our sys admin was trying to get this to work:

@args = ("/usr/local/bin/ldapmodify","-a -n -x -w", $pass,"-H $url", "-f $file");

print "@args";
system(@args);

The system call would fail (illegal option -), but when he copied and pasted the output of the print statement to a shell, it worked.

We kept thinking "there's more than one argument to system(), so it's not going through /bin/sh before being exectuted...".

After reading the perldoc for system() and then the man page for execvp(), we realized what was happening was that ldapmodify was being told that it's first argument was "-a -n -x -w", and of course it wasn't subsequently breaking it apart into pieces...because it expected that the shell already did that.

So, even thought the perldoc for system says to place each argument into @args, it doesn't stress strongly enough that every single argument must be an element of the array:

@args = ("/usr/local/bin/ldapmodify","-a", "-n", "-x", "-w", $pass,"-H", $url", "-f", $file);


other biting method

merlyn on 2003-02-07T18:43:36

Is presuming with a multi-arg system that you can do something like:
system "somecommand", "arg1", "arg2", ">outputfile";
Uh, no. That redirection is a shell thingy. No shell, no redirection!