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

Re: Splitting up quoted/escaped command line arguments

by Eily (Hermit)
on Feb 11, 2014 at 18:43 UTC ( #1074466=note: print w/ replies, xml ) Need Help??


in reply to Splitting up quoted/escaped command line arguments

This is just a series of simple splits and/or regexen.

This probably isn't as easy as you think it is. There are already more than one way to make your code "fall on its face".
If the path to the program the user wants to call has spaces, you'll end up breaking it in two, whether the user added quotes or backslashes where needed. But maybe the users are supposed to run a list of carefully chosen programs.
If an argument is "the 'simple' solution", it will be broken into ('simple', 'the solution').
Even if you checked that a " wasn't preceded by a backslash correctly (you wrote [^\]*", which should be a syntax error because the \ has to be escaped, and * means that the " may or may not be preceded by something else than a backslash), it would failed with something like "\\".

So if you find one, do use a module that does the job for you, but I'm afraid I don't know any, and as far as I looked, argv did not seem to be what you are looking for. I may be wrong on that point.


Comment on Re: Splitting up quoted/escaped command line arguments
Select or Download Code
Re^2: Splitting up quoted/escaped command line arguments
by Tommy (Chaplain) on Feb 11, 2014 at 18:53 UTC

    Sorry for forgetting the \\ escape. The command will never have spaces in it--only the arguments.

    I too took a look at the Argv module and tried it out. It doesn't satisfy the needs I have:

    $ perl -MArgv -MData::Dumper -E 'say Data::Dumper::Dumper [ Argv->new( + "/usr/local/bin/ssh %s \"/opt/something/bin/somebinary || echo \"Cou +ld not execute somebinary.\"" )->argv ]' $VAR1 = [ '/usr/local/bin/ssh %s "/opt/something/bin/somebinary || ech +o "Could not execute somebinary."' ];

    Tommy
    A mistake can be valuable or costly, depending on how faithfully you pursue correction

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (11)
As of 2014-08-20 13:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (113 votes), past polls