Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

mako132 (2925)

Journal of mako132 (2925)

Friday February 07, 2003
12:36 PM

system() bites us

[ #10464 ]
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";

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);

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • 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!
    • Randal L. Schwartz
    • Stonehenge