Search code examples
linuxperlsystemgnu-screen

perl exec screen with parameters


If I run the following:

system("screen -dmS $screenname");

it works as it should be but when I try to run a screen from perl and to execute a command (in this case tcpreplay) with some extra arguments it doesn't run as it's supposed to.

system("screen -dmS $screenname -X stuff \"`printf \"tcpreplay --intf1=eth0 s.cap\\r\"`\" ");

What am I doing wrong here?


Solution

  • Simo A's answer is probably right with regards to the issue, but I like to use the following when working with screen opposed to using the -X flag. Explicitly telling it the command language interpreter.

    Why use -c you ask?

    If the -c option is present, then commands are read from string. If there are arguments after the string, they are assigned to the positional parameters, starting with $0.

    system("screen -dmS $screenname sh -c 'PRETTY MUCH ANYTHING WORKS'");
    

    I figured I'd shared as I run alot of Perl system commands and the above always works for screen commands.