# Off topic: running non-ruby programs through command line

**URL:** <https://www.ruby-forum.com/t/off-topic-running-non-ruby-programs-through-command-line/101940>\
**Category:** Rails\
**Created:** [August 8, 2006, 8:21pm UTC](https://www.ruby-forum.com/t/off-topic-running-non-ruby-programs-through-command-line/101940 "2006-08-08T20:21:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![typej](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f1d935/32.png) [@typej](https://www.ruby-forum.com/u/typej)\
**Post date:** [August 8, 2006, 8:21pm UTC](https://www.ruby-forum.com/t/off-topic-running-non-ruby-programs-through-command-line/101940/1 "2006-08-08T20:21:25Z")

</div>

Hi all,

Slightly OT, but is there any way to run command-line programs through  
Ruby?  
I have a rails web application that performs some database work. After a  
certain action is performed, the rails app should then call a java  
program  
that performs additional work to our mainframe. This is under Win 2003  
Server.

Any ideas?

Thanks,  
Jin L.

---

<div class="post-metadata">

**Author:** ![typej](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f1d935/32.png) [@typej](https://www.ruby-forum.com/u/typej)\
**Post date:** [August 8, 2006, 8:25pm UTC](https://www.ruby-forum.com/t/off-topic-running-non-ruby-programs-through-command-line/101940/2 "2006-08-08T20:25:53Z")

</div>

I think %x{ command } does this

---

<div class="post-metadata">

**Author:** ![typej](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f1d935/32.png) [@typej](https://www.ruby-forum.com/u/typej)\
**Post date:** [August 8, 2006, 8:54pm UTC](https://www.ruby-forum.com/t/off-topic-running-non-ruby-programs-through-command-line/101940/3 "2006-08-08T20:54:28Z")

</div>

On Tue, 2006-08-08 at 10:26 -0700, Jin L. wrote:

> Hi all,
> 
> Slightly OT, but is there any way to run command-line programs through  
> Ruby? I have a rails web application that performs some database work.  
> After a certain action is performed, the rails app should then call a  
> java program that performs additional work to our mainframe. This is  
> under Win 2003 Server.

You can probably use

system(…)

see Kernel.system for docs. Or backticks

`java -jar whatever.jar`

bye  
John

---

<div class="post-metadata">

**Author:** ![typej](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f1d935/32.png) [@typej](https://www.ruby-forum.com/u/typej)\
**Post date:** [August 15, 2006, 2:18pm UTC](https://www.ruby-forum.com/t/off-topic-running-non-ruby-programs-through-command-line/101940/4 "2006-08-15T14:18:43Z")

</div>

Hi.  
It’s not a good idea, IMHO, to call an external app on a http session.  
You will hang your session unless you work with threads / forks.

A good way is:

- Drop a file on a directory with all parameters you need.
- Create an robot that reads the directory from time to time and calls  
your java app with parameters is file.  
– Before calling the java app is good to move the dropped file to avoid  
getting the same file several times.

This is ok if you need it asynchronous.

[]'s  
Romeu Fonseca

-----Mensagem original-----  
De: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] Em nome de Jin L.  
Enviada em: terça-feira, 8 de agosto de 2006 13:26  
Para: removed\_email\_address@domain.invalid  
Assunto: [Rails] off topic: running non-ruby programs through command  
line

Hi all,

Slightly OT, but is there any way to run command-line programs through  
Ruby? I have a rails web application that performs some database work.  
After a certain action is performed, the rails app should then call a  
java program that performs additional work to our mainframe. This is  
under Win 2003 Server.

Any ideas?

## Thanks, Jin L.

No virus found in this incoming message.  
Checked by AVG Free Edition.  
Version: 7.1.405 / Virus Database: 268.10.7/411 - Release Date: 7/8/2006

–  
No virus found in this outgoing message.  
Checked by AVG Free Edition.  
Version: 7.1.405 / Virus Database: 268.10.7/411 - Release Date: 7/8/2006

---

<div class="post-metadata">

**Author:** ![typej](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f1d935/32.png) [@typej](https://www.ruby-forum.com/u/typej)\
**Post date:** [August 15, 2006, 2:22pm UTC](https://www.ruby-forum.com/t/off-topic-running-non-ruby-programs-through-command-line/101940/5 "2006-08-15T14:22:10Z")

</div>

2006/8/8, Romeu Henrique Capparelli F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> – Before calling the java app is good to move the dropped file to avoid  
> getting the same file several times.

another way: use the backgrounDRb plugin. so you can even make cron-like  
things, status reporting back to the app, etc
