On Thu, Feb 10, 2011 at 12:48 AM, Gerad S. <geradstemke / gmail.com> wrote:
> Hi All,
>
> I am trying to add functionality to an interesting script.   
> that is tripping me up is that I have to make a system call to echo, and
> feed several parameters.      
> the ` character.
>
> Because of this, the syntax of:
>
> `echo "#{someVar}" | ./some-script.py > "#{outputFile}"`
>
> is breaking when #{someVar} contains the tick `.   > command to fail because it executes up to the tick ` in someVar and not
> to the end as intended.
>
> I have also tried using the system() command as follows:
>
> system("echo \"#{someVar}\" | ./some-script.py > \"#{outputFile}\"")

Why do you escape the string interpolation?  Don't you want those file
names inserted there?  It seems you rather want

system("echo '#{someVar}' | ./some-script.py >'#{outputFile}'")


> But this fails when there is a tick ` in #{someVar} as well.

Here's a pure Ruby solution:

File.open outputFile, "w" do |out|
  IO.popen "./some-script.py", "rw" do |io|
    t = Thread.new do
      IO.copy_stream(io, out, 1024)
      # pre 1.9:
      # while ( b = io.read(1024) )
      #   out.write(b)
      # end
    end

    io.puts(someVar)
    io.close_write

    t.join
  end
end

Of course, it would be even better if you rewrote the Python script in Ruby. ;-)

Cheers

robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/