From: Justin Collins Date: 2009-01-07T19:28:05+09:00 Subject: Re: A question about running external program Zhao Yi wrote: > I use this method to run an external program: > > output=`uname -r | sed 's/\([^\.]*\.[^\.]*\)\.*.*/\1/'` > puts output > > ruby will ignore the sed command. Doesn't ruby support "|"? > The sed command is not being ignored. The issue is that the backticks (`) do string interpolation before sending the command, which means your backslashes are removed before the commands are sent to the shell. Take a look at this: irb(main):001:0> puts `uname -r | sed 's/\([^\.]*\.[^\.]*\)\.*.*/\1/' && ps x | grep uname` 2.6.27.5-desktop-2mnb 24178 pts/8 S+ 0:00 sh -c uname -r | sed 's/([^.]*.[^.]*).*.*/?/' && ps x | grep uname 24182 pts/8 S+ 0:00 grep uname => nil irb(main):002:0> puts system 'uname -r | sed "s/\([^\.]*\.[^\.]*\)\.*.*/\1/" && ps x | grep uname' 2.6 24187 pts/8 S+ 0:00 sh -c uname -r | sed "s/\([^\.]*\.[^\.]*\)\.*.*/\1/" && ps x | grep uname 24191 pts/8 S+ 0:00 grep uname true => nil irb(main):003:0> puts `uname -r | sed 's/\\([^\\.]*\\.[^\\.]*\\)\\.*.*/\\1/' && ps x | grep uname` 2.6 24201 pts/8 S+ 0:00 sh -c uname -r | sed 's/\([^\.]*\.[^\.]*\)\.*.*/\1/' && ps x | grep uname 24205 pts/8 S+ 0:00 grep uname => nil -Justin