escapeshellcmd() for Ruby

H

hawe

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
 
J

James Edward Gray II

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

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

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

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

James Edward Gray II=
 
B

Brian Candler

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top