Topic: how to executing system command

Hello,

I'm really new for rails and I know that this is not the first time about this question, but please, I really need your helps. I've tried to executed the unix command via rails using exec() and system() but didn't work. Could anybody please suggest me how to execute unix command (I'd like to run a shell script) and get it's result to display in the view. Thanks in advance for any help you can offer.

pekopeko

Re: how to executing system command

try this:

puts %x[pwd]
puts `whoami`

Two solutions

Re: how to executing system command

Here is an article with a few explained methods on how to run shell commands.

If you don't need advanced stuff, backticks (as you see above) are the best way to run shell commands and get the output (STDOUT).

Re: how to executing system command

Hi oscardb and ropiku

Thanks for you replies. My problem has been solved smile.

Re: how to executing system command

hi pekopeko,
i have the same problem i am new in rails programming too,
let me know how solev your problem and decsribe step by step how to call script from rails ?
descript my problem:
=====================
in a rails web application programming i need to run bash script (on the linux OS ) in the rails envitonment, but i dont know how to connect my script to the rails in order to rails read & run my script then send the output of script to rails so that meet my needs.

for example i have server with ip:1.1.1.1 ,and write script in the path: /usr/local/scripts /hello.sh ,whenever i run hello.sh script on this server print " hello world" in output, but my rails applicaton is running on the server with ip :1.1.1.2 for example ,now i need to run hello.sh via the rails web application on server 1.1.1.2 to send me on the webpage the output: "hello world" ... that is simple example to say what i need.

myscript: for example

#!/bin/bash
echo "hello world"
OS=LINUX

,please help me,i am new in rails programming thansk for your help,

Last edited by saamimh (2011-11-16 04:09:36)