Hi Sudhindra, Depending on the needs/requirements of what you're trying to do, you could probably get away with exec'ing your ruby file in a subshell and direct output as needed.
Take a look at Kernel module backtics (http://www.ruby-doc.org/core/ classes/Kernel.html#M006001) and read up on various options regarding (sub)processes (altho old pickaxe book ... http://www.rubycentral.com/pickaxe/tut_threads.html). Simple example: $ cat sum.rb puts "#{ARGV[0].to_i} + #{ARGV[1].to_i} = #{ARGV[0].to_i + ARGV [1].to_i}" $ ruby sum.rb 4 5 4 + 5 = 9 $ irb > `ruby sum.rb 3 4 > sum_output.txt 2>&1` => "" > res = IO.read('sum_output.txt') => "3 + 4 = 7\n" Note however that using backtics you can directly capture the output of what was exec'd in the subshell if you want, instead of writing it to some file and then reading it back in: > res = `ruby sum.rb 3 4 2>&1`.chomp => "3 + 4 = 7" That said, I second Michael's hope-you-know-what-you're-doing. Cheers, Jeff On Mar 2, 7:39 pm, Sudhi Kulkarni <rails-mailing-l...@andreas-s.net> wrote: > Conrad Taylor wrote: > > On Mon, Mar 2, 2009 at 8:40 AM, Sudhi Kulkarni < > > rails-mailing-l...@andreas-s.net> wrote: > > >> >> print "hello world" > >> > -- > >> another ruby program. How do I redirect the output to a file instead of > >> stdout and stderr? > > >> Thanks, > >> Sudhindra > >> Thanks for the replies > > > Hi, you should be able to do the following: > > > In file "a", I have the following: > > > def a > > "Hello, " > > end > > > In file "b", I have the following: > > > def b > > "my name is " > > end > > > In file "c", I have the following: > > > require "a" > > require "b" > > > if __FILE__ == $0 > > > if ARGV.length == 1 > > > puts "#{a}#{b}#{ARGV.first}" > > > else > > > puts "Usage: c < your_name >" > > > end > > > end > > > end > > >>> ruby c Sudhindra >& file.txt > > > file.txt contains: Hello, my name is Sudhindra > > > Lastly, I would recommend reading about global constants in "Programming > > Ruby 1.8" or "Programming Ruby 1.9". Also, I would get a good reference > > on > > the Unix > > command set. > > > Good luck, > > > -Conrad > > Hi, > > May be I am not putting the question right. I want to have editor where > I type in text(Ruby) and that is copied to a temp file for execution. > Now within my editor which is also a ruby script I want to execute this > file. So I call > > load 'temp.rb' > > The problem is that this program executes fine but I am not able to > capture the output into a file. > > Can I do something like > > load 'temp.rb >&output.txt ? ( This did not work so what should I do?) > > Thanks, > Sudhindra > > -- > Posted viahttp://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---