Redirecting Output to a file from RUBY COMMAND PROMPT irb(main) Prompt

590 views
Skip to first unread message

Kumar Chandra Yog

unread,
Jun 1, 2014, 9:34:46 AM6/1/14
to calabash...@googlegroups.com
Hi All,

Can anyone please help me how to redirect output  to a file from a Interactive Ruby Command ?

Reason:-sometime querry("*") gives array of 300 elements & it does not fit into window and we know  searching  in DOS window does NOT  work properly .
So if we somehow able to re-direct result to a file it will be good and we can search elements easily . Please help me!! I have used ">" operator but failed...
C:\Documents and Settings\a\Desktop>irb
irb(main):001:0> puts "Hello World"
Hello World
=> nil
irb(main):002:0> puts Time.now
2014-06-01 18:51:22 +0530
=> nil

irb(main):003:0> puts Time.now > aaa.txt
NameError: undefined local variable or method `aaa' for main:Obje
        from (irb):3
        from C:/Ruby193/bin/irb:12:in `<main>'

irb(main):004:0> exit

C:\Documents and Settings\a\Desktop>type a.rb
puts "hello world"
C:\Documents and Settings\a\Desktop>ruby a.rb aaa.txt
hello world

C:\Documents and Settings\a\Desktop>ruby a.rb > aaa.txt

C:\Documents and Settings\a\Desktop>quit


WorkAround -- You can use "break" key to see partial page output,but it will be really difficult task. I pressed "Break" key more than 30 times to see all id as .Real pain....



Regards,
Kumar
Unable to REDIRECT query Output from Interactive Ruby Command Prompt.bmp

Jani Jegoroff

unread,
Jun 1, 2014, 2:38:03 PM6/1/14
to calabash...@googlegroups.com
Not a complete solution but step to the right direction. Should help you to go further...

irb(main):015:0> $stdout = File.open("console.log","w") #define output file
irb(main):016:0> query '*' #query all elements
irb(main):017:0> $stdout.flush # write output to the file
irb(main):018:0> $stdout = STDOUT # back to the original state
#<IO:<STDOUT>>
irb(main):019:0>

Tulika jaipuriar

unread,
Dec 8, 2015, 6:23:53 AM12/8/15
to calabash-android, kchan...@gmail.com
Hi, did you get a solution for this?
If yes, then kindly share.
Reply all
Reply to author
Forward
0 new messages