[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

escapeshellcmd() for Ruby

hawe

4/11/2007 12:20:00 PM

Hi!

Is there something like PHP's escapeshellcmd() function which removes
special signs for system calls? Or do I have to do it myself and escape
|;>"? What else?

Thanks a lot,
hawe

--
Posted via http://www.ruby-....

2 Answers

James Gray

4/11/2007 12:33:00 PM

0

On Apr 11, 2007, at 7:20 AM, hawe wrote:

> Is there something like PHP's escapeshellcmd() function which removes
> special signs for system calls? Or do I have to do it myself and
> escape
> |;>"? What else?

I'm not aware of anything, but TextMate uses to following code for
shell escaping:

# escape text to make it useable in a shell script as one
“word” (string)
def e_sh(str)
str.to_s.gsub(/(?=[^a-zA-Z0-9_.\/\-\x7F-\xFF\n])/, '\\').gsub(/\n/,
"'\n'").sub(/^$/, "''")
end

Not sure how portable that is, but hopefully it will get you started.

James Edward Gray II

Brian Candler

4/11/2007 2:52:00 PM

0

On Wed, Apr 11, 2007 at 09:20:05PM +0900, hawe wrote:
> Is there something like PHP's escapeshellcmd() function which removes
> special signs for system calls? Or do I have to do it myself and escape
> |;>"? What else?

You can use system("/usr/bin/foo","bar","baz"). This runs command
"/usr/bin/foo" and passes it arguments "bar" and "baz", without going
through a shell at all - so shell escaping isn't required.

irb(main):002:0> system("/bin/echo","hello","2>/dev/null","world")
hello 2>/dev/null world
=> true