2

I was wondering if there were a simple way to open a second terminal to display data. So I have a program running in a terminal, and I was wondering if it'd be possible for that program to open a second terminal to which I could output information for the user to read (leaving the other terminal alone).

Sergio Tulentsev
  • 226,338
  • 43
  • 373
  • 367
Jean-Luc
  • 3,563
  • 8
  • 40
  • 78
  • 2
    You could log that output information to a file, and in another terminal session tail that file. – Sergio Tulentsev Nov 07 '12 at 23:29
  • Yeah, was wondering if there was a more direct method. Like literally puts [terminal 2] "blah". Nonetheless, I may have to do what you've suggested! Thanks for the suggestion. – Jean-Luc Nov 07 '12 at 23:32
  • For this, you'd have to get into system specifics. On Linux, for exampe, you could start a child of gnome-terminal. – Linuxios Nov 08 '12 at 00:04
  • We're going to need to your operating system and the terminal (xterm, gnome, etc). – sunnyrjuneja Nov 08 '12 at 02:40

2 Answers2

2

Okay, I don't know what operating system you're using or what's your console of choice, but on my Ubuntu 12.10 installation this opened up an xterm window with my results:

a = "Hello World!"

system(%Q[xterm -hold -e /bin/bash -l -c "echo #{a}"])

As for an explanation:

  • -hold prevents the window from closing as soon as the program executes.
  • -e specifies what program and its arguments are to be run (the /bin/bash ... part.).
  • /bin/bash invokes the unix shell bash
  • -l makes bash act as if it had been invoked as a login shell
  • -c will receive console output
  • echo displays a message on the screen.

Check the man pages for xterm and bash for more information.

If you add more details, perhaps we can clarify a better answer although, truthfully, I prefer Sergio's answer of outputting to a file and having another console tailing that file.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
sunnyrjuneja
  • 6,033
  • 2
  • 32
  • 51
  • Yeah using the same operating system as you! It works perfectly! Though I was hoping for a more portable solution. I shall probably do what Sergio Tulentsev suggested; nonetheless, this answers my question. Thanks! – Jean-Luc Nov 08 '12 at 05:07
1

I'd strongly be inclined to do as Mr Tulentsev suggests in the first comment, but if you'd like to do so from ruby, look here for information on how to start a new process from ruby.

hd1
  • 33,938
  • 5
  • 80
  • 91
  • Let's say he does start a child process. How to bind this child to another terminal session (so that output goes there)? – Sergio Tulentsev Nov 07 '12 at 23:40
  • One would use the [answer to this question](http://stackoverflow.com/questions/4234119/ruby-pipes-how-do-i-tie-the-output-of-two-subprocesses-together) to do that – hd1 Nov 07 '12 at 23:42
  • I'm afraid I still don't see it. Nowhere in that topic is there a hint of multiple terminal sessions. Anyway, tailing the file is the way to go. Anything else is overcomplicating. :) – Sergio Tulentsev Nov 07 '12 at 23:44