From: "Suraj N. Kurapati" Date: 2006-10-09T08:44:20+09:00 Subject: Re: ruby/GTK : Embedded terminal or redirecting process output -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Mickael Faivre-Macon wrote: > Using ruby-gnome2 (gtk) I'd like to embed a terminal in a window, or > redirect the output of a child process into a text editor. > > Something like > sbtn.signal_connect("pressed") { > system('ls') > } > > ... launch the command 'ls' but is not portable and If you just want to get a list of files in a directory, Ruby provides the portable Dir#entries method. > I don't know how to > redirect the output into a gtk text editor, not in the original > terminal window. I'm sure the gtk text editor has some #append or #insert method which lets you add text to it. Use that. > > Something like > sbtn.signal_connect("pressed") { > lsproc = IO.popen('ls') > p Process.waitpid(lsproc.pid) > p $? > } > ... is portable, but still does not redirect the output. IO.popen('ls') do |f| puts f.read end If you want to "pipe" some data to the subprocess: request = "i want ice cream!" IO.popen('cat', 'r+') do |f| f.write request f.close_write response = f.read puts "cat said: #{response}" end -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.2 (GNU/Linux) iD8DBQFFKY1OmV9O7RYnKMcRAn05AKCP1Qnc4TTVvIYcKtWrVC8RKMZFOQCfYWAk Ln8UdA+jfmrRfawr1VYoPgc= =EHSf -----END PGP SIGNATURE-----