Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: system commands/shell and perl variables.

by choroba (Cardinal)
on Jan 21, 2019 at 21:42 UTC ( [id://1228784]=note: print w/replies, xml ) Need Help??


in reply to system commands/shell and perl variables.

Does your editor support syntax highlighting? Double quotes can't be nested in Perl, and backticks aren't paired inside double quotes as in the shell. Fortunately, Perl has the qq operator:
my $XENDOMID = qq(xl list| DOM_ID=`fgrep $vm_run` | awk '{print $2}'` +&& VNCPORT=`ps x \ | fgrep -m 1 "domid $DOM_ID" | awk '{print $1}'` && sockstat -4l | fgr +ep $VNCPORT | awk '{print $6}');
But I'm not sure it works, xl isn't a recognised command on my system.

Calling grep and awk from perl seems suspicious. Perl can do most of the operations these commands do, and without shelling out to run them, it's usually faster. Please provide a SSCCE so we can help you more.

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^2: system commands/shell and perl variables.
by NetWallah (Canon) on Jan 22, 2019 at 06:42 UTC
    In addition to what choroba pointed out,

    the $ (Dollar sigil) in the shell code need to be escaped .. otherwise they will be interpreted by perl.

    So - in this case - your passing of the value of $vm_run and $VNCPORT should work OK, but $DOM_ID, $2, $1, and $6 SHELL variables all need to have their $ escaped (pre-pending a "\").

                    As a computer, I find your faith in technology amusing.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1228784]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-04-20 04:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found