in reply to Re: how to pass colon and comma in exec args
in thread how to pass colon and comma in exec args

So, of course, I simplified things a bit in the post. I'm using variables for this:

exec qw{$tcpreplay -p $pps -i $eth -N $src_ip/32:$src,$dest_ip/32:$users->{$user}->{nets}{$src} $users->{$user}->{authcap} $datacap 2>&1}

would be the equiv to your response in my code.

That doesn't work, tho'. I get an error about 'No such file or directory' - but the binary is in the location specified in the variable.

I've also gone the route of creating an @arg array with each token in it, and call it so:

exec(@args) or die .....

and I get the result that I posted.

Thanks!
  • Comment on Re^2: how to pass colon and comma in exec args

Replies are listed 'Best First'.
Re^3: how to pass colon and comma in exec args
by billbabcock (Acolyte) on Nov 05, 2004 at 06:30 UTC
    I also tried the qw with a different delimiter to avoid confusion and collision with my variables. :-)
      'man perlop' says qw{} doesn't interpolate variables.
      If you want to avoid the shell messing up your arguments, you could try the 'indirect object'-form of exec.
      my $cmd = '/usr/bin/tcpreplay'; # or whereever exec {$cmd} ($cmd, '-p', $pps, '-i', $eth); # and so on...
      Note there is no comma after the first arg to exec. With this form exec will not use the shell and pass the list of args unchanged as argv[] to the command. This means you have to supply a value for argv[0], too (something one might forget coding too much perl...) Hope this helps....