Ruby - writing output to a new terminal window

I was wondering if a ruby โ€‹โ€‹script could open a new terminal window and redirect its output to that newly opened terminal window.

To open a new terminal I am currently executing system("gnome-terminal")

, however, after researching for a while, I still don't know how I could achieve the following ("pseudo code"):

variable = "test"
newTerminal = system("gnome-terminal")
puts variable to newTerminal

      

Is it possible even without major problems?

+3


source to share


2 answers


To do something like this on OSX (in case anyone is facing the same situation, yes, I know this does not answer this particular situation) you can do:

variable = "test"
`osascript -e 'tell app "Terminal"
  do script "echo #{variable}"
end tell'`

      



Note. This is not exactly the same as using puts

, as it would actually echo multiple times if you wanted to print multiple things, but this is more of a basis for solving a similar problem.

+1


source


I can't easily test this for your system, but I'll try using IO.popen to open a terminal, which should allow you to write to the IO input stream.



0


source







All Articles