Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

What should I know about "secure" system()?

by Anonymous Monk
on Apr 18, 2012 at 17:18 UTC ( #965748=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

My humble greetings, monks,

I am trying to automate a command-line Java application (Project X to be exact), and am trying to use the secure form of system() or pipe from it. However, when I do that, I am merely greeted with an error from Java:

Failed to load Main-Class manifest attribute from ~/src/Project-X_0.91.0/ProjectX.jar

Here's what I am trying:

# works system("java -jar ~/src/Project-X_0.91.0/ProjectX.jar -demux"); # doesn't work system(qw#java -jar ~/src/Project-X_0.91.0/ProjectX.jar -demux#); # doesn't work open($fh, '-|', qw#java -jar ~/src/Project-X_0.91.0/ProjectX.jar -demu +x#); print while (<$fh>); close $fh;

What could be the cause of difference in execution? The Java I'm using is GCJ version 4.4.5, for what it is worth.

Comment on What should I know about "secure" system()?
Select or Download Code
Replies are listed 'Best First'.
Re: What should I know about "secure" system()?
by Anonymous Monk on Apr 18, 2012 at 17:39 UTC

    D'oh. Forgot that I had a ~ in there which is only expanded by the shell -- should substitute with $ENV{HOME} or something. Consider this one solved.

Re: What should I know about "secure" system()?
by Riales (Hermit) on Apr 18, 2012 at 17:30 UTC

    The second one doesn't work because qw returns a quoted list - so you're actually trying to execute this:

    system('java, '-jar', '~/src/Project-X_01.0/ProjectX.jar', '-demux');

    I think you meant to do this (which should work):

    system(q#java -jar ~/src/Project-X_01.0/ProjectX.jar -demux#);

    Edit: My apologies. TIL system also takes a list.

      Edit: My apologies. TIL system also takes a list.

      And that would be the secure form of invocation I was talking about =)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (15)
As of 2015-07-31 14:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (278 votes), past polls