I would like to open a terminal from my ruby script, display the script outputs and exit the terminal at the end of the script.
# open xterm -> `mate-terminal -e " ... "`
a = ''
while a != 'q'
a = STDIN.getch
puts "Hello World !" # output in xterm
end
# quit xterm
Is this possible or do I have to do a script to call another one?
EDIT:
I can do with two scripts :
test1.rb
#!/usr/bin/env ruby
`mate-terminal -e "bash -c 'ruby test2.rb'"`
test2.rb
#!/usr/bin/env ruby
puts "hello world"
gets
run first script
$ ruby test1.rb
But is it possible to do this with a single script?
EDIT2 :
I try to do that
#!/usr/bin/env ruby
obj1 = "object 1"
obj2 = "object 2"
file = <<EOF
#!/usr/bin/env ruby
require 'io/console'
a = ''
while a != 'q'
puts "Do you want to see obj1, obj2 or quit ? .. enter 1, 2 or q"
a = STDIN.getch
case a
when '1' then puts "#{obj1}"
when '2' then puts "#{obj2}"
end
end
EOF
File.open('display.rb', 'w') { |f| f.puts file }
`mate-terminal -e "bash -c 'ruby display.rb'"`
It works, but it's really not beautifull.
Is there another way?