Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Is it possible to execute some command in qx argument

by bart (Canon)
on May 05, 2017 at 10:44 UTC ( #1189561=note: print w/replies, xml ) Need Help??


in reply to Is it possible to execute some command in qx argument

If this is on Linux, as I think it is, there's trickery you can do by passing an argument containing substrings like `command args` or $(command args) (In the Linux shell, use single quotes on the command line to pass them). They will be executed by the shell called from the Perl script, in addition to the normal behaviour of the original call.

Replies are listed 'Best First'.
Re^2: Is it possible to execute some command in qx argument
by vladimirfedorov (Novice) on May 06, 2017 at 00:39 UTC
    Do you mean something like the code below? I tried that and it didn't work. Meaning it still produced one directory with the name "currentdate0 0 492mkdir otherdir1)"
    my $cmd = "mkdir "; $arg = "$(mkdir otherdir1)"; qx($cmd "currentdate$arg");
      $arg = "$(mkdir otherdir1)";
      Use single quotes in Perl, or the "$(" won't stick. And do something that produces output as well, to use in the name of the new directory.
      $arg = '$(mkdir otherdir1; date +%F_%H.%M.%S)';
      This also shows the need to cleanup (AKA "untaint") the user entered input data before just executing it. You could be executing a lot more than you bargained for.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2020-06-05 19:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?



    Results (40 votes). Check out past polls.

    Notices?