# ruby/GTK : Embedded terminal or redirecting process output

**URL:** <https://www.ruby-forum.com/t/ruby-gtk-embedded-terminal-or-redirecting-process-output/71364>\
**Category:** Ruby\
**Created:** [October 7, 2006, 7:16pm UTC](https://www.ruby-forum.com/t/ruby-gtk-embedded-terminal-or-redirecting-process-output/71364 "2006-10-07T19:16:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![micktaiwan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4af34b/32.png) [@micktaiwan](https://www.ruby-forum.com/u/micktaiwan)\
**Post date:** [October 7, 2006, 7:16pm UTC](https://www.ruby-forum.com/t/ruby-gtk-embedded-terminal-or-redirecting-process-output/71364/1 "2006-10-07T19:16:28Z")

</div>

Hi,

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 I don’t know how to  
redirect the output into a gtk text editor, not in the original  
terminal window.

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.

Could someone give me a pointer to begin with ?

Thanks,  
Mickael.

---

<div class="post-metadata">

**Author:** ![micktaiwan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4af34b/32.png) [@micktaiwan](https://www.ruby-forum.com/u/micktaiwan)\
**Post date:** [October 9, 2006, 1:44am UTC](https://www.ruby-forum.com/t/ruby-gtk-embedded-terminal-or-redirecting-process-output/71364/2 "2006-10-09T01:44:39Z")

</div>

-----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-----

---

<div class="post-metadata">

**Author:** ![micktaiwan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4af34b/32.png) [@micktaiwan](https://www.ruby-forum.com/u/micktaiwan)\
**Post date:** [October 10, 2006, 4:13am UTC](https://www.ruby-forum.com/t/ruby-gtk-embedded-terminal-or-redirecting-process-output/71364/3 "2006-10-10T04:13:23Z")

</div>

Hi,

2006/10/8, Mickael Faivre-Macon [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Hi,
> 
> 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.

What about Ruby/VTE? Ruby/VTE is included in Ruby-GNOME2 since  
0.15.0.

Thanks,
