Comments on: 6 Ways to Run Shell Commands in Ruby http://pasadenarb.com/2007/03/ruby-shell-commands.html The Pasadena Ruby Brigade Fri, 21 Nov 2008 11:24:52 +0000 http://wordpress.org/?v=2.1.2 By: Ilya http://pasadenarb.com/2007/03/ruby-shell-commands.html#comment-2 Ilya Wed, 14 Mar 2007 08:58:00 +0000 http://pasadenarb.com/2007/03/ruby-shell-commands.html#comment-2 Thank you! Nice review. Thank you! Nice review.

]]>
By: Wayne E. Seguin http://pasadenarb.com/2007/03/ruby-shell-commands.html#comment-32 Wayne E. Seguin Thu, 05 Jul 2007 22:07:23 +0000 http://pasadenarb.com/2007/03/ruby-shell-commands.html#comment-32 Don't forget the <code>%x{whoami}<code> which is the delimited form of the backquote <code>`whoami`</code>. Don’t forget the %x{whoami} which is the delimited form of the backquote `whoami`.

]]>
By: Marius http://pasadenarb.com/2007/03/ruby-shell-commands.html#comment-131 Marius Fri, 07 Sep 2007 11:11:37 +0000 http://pasadenarb.com/2007/03/ruby-shell-commands.html#comment-131 Hey! Thanks for the overview! Do you happen to know how I can pass a ruby variable to the shell command that needs to be executed? Something like this: filename = 'test.tar' result = `tar xfv` + filename Of course this does not work, but how do I make it work ? ;) I have been googling for 30 minutes now and I can't find anything. Greetings from Bonn (DE) Hey! Thanks for the overview! Do you happen to know how I can pass a ruby variable to the shell command that needs to be executed? Something like this:

filename = ‘test.tar’ result = `tar xfv` + filename

Of course this does not work, but how do I make it work ? ;) I have been googling for 30 minutes now and I can’t find anything. Greetings from Bonn (DE)

]]>
By: Michael http://pasadenarb.com/2007/03/ruby-shell-commands.html#comment-156 Michael Sat, 15 Sep 2007 00:18:40 +0000 http://pasadenarb.com/2007/03/ruby-shell-commands.html#comment-156 Marius - you can use exit_code = system("tar xfv #{filename}") Make sure to use double quotes, not single quotes. If you need to capture output, use Open3.popen with the same double-quoted string. Marius - you can use

exit_code = system(”tar xfv #{filename}”)

Make sure to use double quotes, not single quotes.

If you need to capture output, use Open3.popen with the same double-quoted string.

]]>
By: Jason Campbell http://pasadenarb.com/2007/03/ruby-shell-commands.html#comment-178 Jason Campbell Sat, 22 Sep 2007 07:50:30 +0000 http://pasadenarb.com/2007/03/ruby-shell-commands.html#comment-178 Thanks! Seriously. I found this after almost an hour of scouring google. This is just what I needed! I added a line to Simon Gate's <a href="http://simongate.com/2007/6/5/basecamp-post-commit-hook" rel="nofollow">Basecamp post-commit hook</a> to automatically update a working copy of my repository using the backtick method. I saw the method before but since I am a noob to ruby I didn't quite get it until I found your article. Thanks again! Thanks! Seriously. I found this after almost an hour of scouring google. This is just what I needed!

I added a line to Simon Gate’s Basecamp post-commit hook to automatically update a working copy of my repository using the backtick method. I saw the method before but since I am a noob to ruby I didn’t quite get it until I found your article. Thanks again!

]]>
By: Floyd http://pasadenarb.com/2007/03/ruby-shell-commands.html#comment-194 Floyd Fri, 28 Sep 2007 02:41:58 +0000 http://pasadenarb.com/2007/03/ruby-shell-commands.html#comment-194 Nice summary. It was helpful. Nice summary. It was helpful.

]]>
By: Garrett Smith http://pasadenarb.com/2007/03/ruby-shell-commands.html#comment-239 Garrett Smith Thu, 18 Oct 2007 17:46:13 +0000 http://pasadenarb.com/2007/03/ruby-shell-commands.html#comment-239 Good write-up, but you forgot to mention that a few of these methods don't work on certian OSes, such as Windows. Good write-up, but you forgot to mention that a few of these methods don’t work on certian OSes, such as Windows.

]]>
By: james http://pasadenarb.com/2007/03/ruby-shell-commands.html#comment-250 james Sun, 21 Oct 2007 11:45:51 +0000 http://pasadenarb.com/2007/03/ruby-shell-commands.html#comment-250 Very useful - Answered a lot of key questions Very useful - Answered a lot of key questions

]]>
By: JeanW http://pasadenarb.com/2007/03/ruby-shell-commands.html#comment-1215 JeanW Thu, 14 Feb 2008 20:12:30 +0000 http://pasadenarb.com/2007/03/ruby-shell-commands.html#comment-1215 Great article! We actually ended up going with a simple solution to get our stderr on Windows-- we just redirected stderr to stdout inside the backticsk, e.g. `#{command} #{args} 2>&1` No need to install a new gem on every machine! Great article! We actually ended up going with a simple solution to get our stderr on Windows– we just redirected stderr to stdout inside the backticsk, e.g.

`#{command} #{args} 2>&1`

No need to install a new gem on every machine!

]]>
By: Murilo http://pasadenarb.com/2007/03/ruby-shell-commands.html#comment-1480 Murilo Thu, 28 Feb 2008 01:54:52 +0000 http://pasadenarb.com/2007/03/ruby-shell-commands.html#comment-1480 Good tutorial. You just forgot to metion that I need to do require "open3" at the beginning of Section "Open3"; you only did it at the third block of code. I also couldn't use open4 on Debian, even after doing gem instal open4, does someone know the reason? (I don't have any experience on Ruby programming, just found the article and tried it out) Good tutorial. You just forgot to metion that I need to do require “open3″ at the beginning of Section “Open3″; you only did it at the third block of code. I also couldn’t use open4 on Debian, even after doing gem instal open4, does someone know the reason? (I don’t have any experience on Ruby programming, just found the article and tried it out)

]]>
By: links for 2008-03-11 « Bloggitation http://pasadenarb.com/2007/03/ruby-shell-commands.html#comment-1676 links for 2008-03-11 « Bloggitation Tue, 11 Mar 2008 00:19:22 +0000 http://pasadenarb.com/2007/03/ruby-shell-commands.html#comment-1676 [...] 6 Ways to Run Shell Commands in Ruby (tags: ruby programming) [...] […] 6 Ways to Run Shell Commands in Ruby (tags: ruby programming) […]

]]>
By: IceskYsl http://pasadenarb.com/2007/03/ruby-shell-commands.html#comment-1885 IceskYsl Tue, 08 Apr 2008 15:27:47 +0000 http://pasadenarb.com/2007/03/ruby-shell-commands.html#comment-1885 I notice a error like this: Code: logger.info("rar a #{local_dir_name} #{local_dir_name}") oo= %x{rar a #{local_dir_name} #{local_dir_name}} logger.info("oo=#{oo}") Output: rar a 1207666290_2 1207666290_2 oo= Program aborted can anybody give me a hand? I notice a error like this:

Code: logger.info(”rar a #{local_dir_name} #{local_dir_name}”) oo= %x{rar a #{local_dir_name} #{local_dir_name}} logger.info(”oo=#{oo}”)

Output: rar a 1207666290_2 1207666290_2 oo= Program aborted

can anybody give me a hand?

]]>
By: IceskYsl http://pasadenarb.com/2007/03/ruby-shell-commands.html#comment-1886 IceskYsl Tue, 08 Apr 2008 15:30:29 +0000 http://pasadenarb.com/2007/03/ruby-shell-commands.html#comment-1886 and in my localhost,it's ok,output like this: ------------ rar a 1207667932_2 1207667932_2 oo= RAR 3.70 beta 1 Copyright (c) 1993-2007 Alexander Roshal 8 Jan 2007 Shareware version Type RAR -? for help Evaluation copy. Please register. Creating archive 1207667932_2.rar Adding 1207667932_2/datas.csv OK Adding 1207667932_2/images OK Adding 1207667932_2 OK Done -------- and in my localhost,it’s ok,output like this:

———— rar a 1207667932_2 1207667932_2 oo= RAR 3.70 beta 1 Copyright (c) 1993-2007 Alexander Roshal 8 Jan 2007 Shareware version Type RAR -? for help

Evaluation copy. Please register.

Creating archive 1207667932_2.rar

Adding 1207667932_2/datas.csv OK Adding 1207667932_2/images OK Adding 1207667932_2 OK Done ——–

]]>
By: Max http://pasadenarb.com/2007/03/ruby-shell-commands.html#comment-1924 Max Fri, 11 Apr 2008 16:13:29 +0000 http://pasadenarb.com/2007/03/ruby-shell-commands.html#comment-1924 I'm trying to do what Marius is doing, but executing "tainted" input instead. Does anyone know if there is a way to escape shell arguments so they're safe? Also, you can install the win32-open3 gem to get this to work on Windows, btw. Oh, and nice article :) I’m trying to do what Marius is doing, but executing “tainted” input instead. Does anyone know if there is a way to escape shell arguments so they’re safe?

Also, you can install the win32-open3 gem to get this to work on Windows, btw.

Oh, and nice article :)

]]>
By: daniel rails http://pasadenarb.com/2007/03/ruby-shell-commands.html#comment-1938 daniel rails Mon, 14 Apr 2008 07:59:49 +0000 http://pasadenarb.com/2007/03/ruby-shell-commands.html#comment-1938 Hey Nate, thanks for article, this was exactly what I was searching for! Greets, Daniel Hey Nate, thanks for article, this was exactly what I was searching for! Greets, Daniel

]]>
By: kingtutt http://pasadenarb.com/2007/03/ruby-shell-commands.html#comment-1981 kingtutt Sun, 20 Apr 2008 12:38:07 +0000 http://pasadenarb.com/2007/03/ruby-shell-commands.html#comment-1981 You've restored my faith! And inspired me to use ruby for in place of bash scripting for system administration tasks...and that's just awesome. You’ve restored my faith! And inspired me to use ruby for in place of bash scripting for system administration tasks…and that’s just awesome.

]]>
By: wdso http://pasadenarb.com/2007/03/ruby-shell-commands.html#comment-2742 wdso Thu, 24 Jul 2008 23:12:06 +0000 http://pasadenarb.com/2007/03/ruby-shell-commands.html#comment-2742 Brilliant summary. One question though… what about threads? Brilliant summary. One question though… what about threads?

]]>