Question

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?

Était-ce utile?

La 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.

Autres conseils

Try replacing single \" with \\\". That should do the trick.

Consider the same issue here:

system ("echo Quotation marks: \\\"here\\\" but \"not here\". ");

The output from the former line of code is: Quotation marks: "here" but not here.

Taking Simo A's answer as a starting point, I would use q( ) rather than " ".

system ( q(echo Quotation marks: \"here\" but "not here". ));

This means you don't need to escape the quote twice.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top