Escaping shell characters

  • Thread starter George Moschovitis
  • Start date
G

George Moschovitis

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.
 
R

Robert Klemme

George Moschovitis said:
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
 

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

Forum statistics

Threads
474,169
Messages
2,570,919
Members
47,459
Latest member
Vida00R129

Latest Threads

Top