Run UNIX command

P

Pieter Jongsma

Hi,

I'm looking for a way to execute an UNIX command from a ruby program.
For instance, when the user selected a .tar.gz file, using the untar
command to decompress it.
How can I do that?

Thanks in advance!
pieter.
 
T

Tim Hunter

Pieter said:
Hi,

I'm looking for a way to execute an UNIX command from a ruby program.
For instance, when the user selected a .tar.gz file, using the untar
command to decompress it.
How can I do that?

Thanks in advance!
pieter.
There's a variety of ways to do that, depending on your needs. The
simplest is to use the Kernel.system method:

system("ls")

If you need the stdout output from the command, use backticks:

output = `ls`

If you need more control, check out IO.popen.
 
J

Jonas Roberto de Goes Filho (sysdebug)

Pieter said:
Hi,

I'm looking for a way to execute an UNIX command from a ruby program.
For instance, when the user selected a .tar.gz file, using the untar
command to decompress it.
How can I do that?

Thanks in advance!
pieter.

Use ``. An example:

irb(main):042:0> `date`
=> "Ter Set 11 16:50:30 BRT 2007\n"

Regards,
 

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
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top