Google Answers Logo
View Question
 
Q: Shell-escaping from perl ( No Answer,   2 Comments )
Question  
Subject: Shell-escaping from perl
Category: Computers > Programming
Asked by: lexi-ga
List Price: $3.00
Posted: 29 Jan 2003 17:05 PST
Expires: 28 Feb 2003 17:05 PST
Question ID: 155019
Suppose I want to invoke a shell command from perl and provide some
user-supplied data as input to the shell command.  The user-supplied
input has to be escaped so the shell will not interpret any part of
it.  I already know how to write a regular expression to do this -
this regular expression is littered throughout my code in far too many
places.  What I want to know is if there is a function in a standard
perl module somewhere that will do this.  Every time I copy and paste
my homegrown regular expression, I worry I'm missing part of it, and
it's not terribly readable. (I do not want to take my regular
expression and make my own function out of it - this does not solve
the problem for when I start a batch of new code because I'd have to
cart that function around with me.)

Request for Question Clarification by duncan2-ga on 29 Jan 2003 17:20 PST
How 'standard' a perl module would you need?  Would ShellQuote.pm
suffice, or does the function need to exist in a more generic module?
http://search.cpan.org/author/ROSCH/String-ShellQuote-1.00/ShellQuote.pm

Clarification of Question by lexi-ga on 29 Jan 2003 17:43 PST
Ideally it would be something that I'm likely to find in a
freshly-downloaded distribution (so I won't have to download anything
extra) but it is possible for me to install new modules (a less
desirable option).
Answer  
There is no answer at this time.

Comments  
Subject: Re: Shell-escaping from perl
From: sycophant-ga on 29 Jan 2003 23:07 PST
 
Drat. I could have sworn there was something like that in CGI.pm, but
I can't find anything about it on the web, or in my big old O'Reilly
Perl Resource Kit (normally used as a bookend).

There are heaps of 'recipes' for that however, and you could always
roll your own module, it is often nice to have your own toolkit of
little things to take from one project to another. :)

Oh well, I am sure someone will find what you are looking for.

Regards,
sycophant-ga
Subject: Re: Shell-escaping from perl
From: yatha-ga on 14 Feb 2003 08:04 PST
 
Try \Q your params \E.
If this does not work , I will tell you a more complex way to do that.
This is the most natural way I can think of.

E.g system ("zip -q zip_name.zip \Qfilename\E");

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy