[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Escaping shell characters

George Moschovitis

3/9/2005 2:57:00 PM

Hello everyone,

I have a small question:

I would like to use backtick (`) to execute a command line
program:

Is there a method in the standard ruby distribution that
allows me to escape a string for the command line shell?

for examle escape strings like this:

`my_programm --password=qw;2332;3`

should become

`my_programm --password=qw\;2332\;3`

Btw I need this method to be compatible with Windows too. I can
implement my own method of course, but I was wondering if there
is something available in ste standard libraries.

thanks in advance,
George.
1 Answer

Robert Klemme

3/9/2005 3:50:00 PM

0


"George Moschovitis" <george.moschovitis@gmail.com> schrieb im Newsbeitrag
news:d0n2sh$ako$1@ulysses.noc.ntua.gr...
> Hello everyone,
>
> I have a small question:
>
> I would like to use backtick (`) to execute a command line
> program:
>
> Is there a method in the standard ruby distribution that
> allows me to escape a string for the command line shell?
>
> for examle escape strings like this:
>
> `my_programm --password=qw;2332;3`
>
> should become
>
> `my_programm --password=qw\;2332\;3`
>
> Btw I need this method to be compatible with Windows too. I can
> implement my own method of course, but I was wondering if there
> is something available in ste standard libraries.
>
> thanks in advance,
> George.

If you don't need the output you could use system:

system "your_program", '--password=qw;2332;3'

You might as well use popen although that has some pecularities on Windows
systems.

robert