How do i open a terminal using ruby?

hi-

i want to open up a terminal from ruby if it was not executed in one.
so,

if not STDIN.isatty
  #Open up a terminal
end

do i have to use IO.popen? i would rather not because, i'm using linux
but this ruby script will also be executed on windows. how do i account
for when to use "gnome-terminal" and when to use "cmd"? then, how do i
write to that terminal window?

is there something easier?

thanks!!!

···

--
Posted via http://www.ruby-forum.com/.

I have no idea if this will work, but it's worth a shot ...

Kernel.exec '/bin/bash', '-c', "ruby #{__FILE__} #{ARGV.join(' ')}"

Beware the infinite recursion!

Blessings,
TwP

···

On Jul 21, 2008, at 6:08 PM, Philip Rutkowski wrote:

hi-

i want to open up a terminal from ruby if it was not executed in one.
so,

if not STDIN.isatty
#Open up a terminal
end

do i have to use IO.popen? i would rather not because, i'm using linux
but this ruby script will also be executed on windows. how do i account
for when to use "gnome-terminal" and when to use "cmd"? then, how do i
write to that terminal window?

why?

a @ http://codeforpeople.com/

···

On Jul 21, 2008, at 6:08 PM, Philip Rutkowski wrote:

hi-

i want to open up a terminal from ruby if it was not executed in one.
so,

if not STDIN.isatty
#Open up a terminal
end

do i have to use IO.popen? i would rather not because, i'm using linux
but this ruby script will also be executed on windows. how do i account
for when to use "gnome-terminal" and when to use "cmd"? then, how do i
write to that terminal window?

is there something easier?
thanks!!!

--
we can deny everything, except that we have the possibility of being better. simply reflect on that.
h.h. the 14th dalai lama

Philip Rutkowski wrote:

if not STDIN.isatty
#Open up a terminal
end
[...]
is there something easier?

If I'm not mistaken, on Windows ruby scripts automatically open in a command
window. And most filemanagers on unix ask you whether to open a terminal when
clicking on an executable file. So I don't think there's any need to do what
you're trying to do.

HTH,
Sebastian

···

--
Jabber: sepp2k@jabber.org
ICQ: 205544826

Tim Pease wrote:

Kernel.exec '/bin/bash', '-c', "ruby #{__FILE__} #{ARGV.join(' ')}"

That won't open a terminal windows. It will simply execute bash which will
execute ruby, but if you weren't in a window before, you're still not.

···

--
Jabber: sepp2k@jabber.org
ICQ: 205544826

Sebastian Hungerecker wrote:

Philip Rutkowski wrote:

if not STDIN.isatty
#Open up a terminal
end
[...]
is there something easier?

If I'm not mistaken, on Windows ruby scripts automatically open in a
command
window. And most filemanagers on unix ask you whether to open a terminal
when
clicking on an executable file. So I don't think there's any need to do
what
you're trying to do.

HTH,
Sebastian

I have the same need. I have a script that runs in a terminal right
now, but I eventually want to make it gui (probably with Shoes) and I'll
need an option to click a button and open a command prompt (then run a
command in that command prompt and leave the prompt open for the user to
use).

I haven't even begun converting to the gui part yet though, so I haven't
put much thought into how I'm going to accomplish this. Oh yeah, and
this will need to be cross-platform, too, but it may just be a matter of
writing a slightly different program for each platform.

James

···

--
Posted via http://www.ruby-forum.com/\.

Check out Monkeybars (http://monkeybars.rubyforge.org/\) for GUI stuff. Combine that with Rawr and you should have a slick cross-platform GUI along with native .app/.exe files and/or a web start link. Monkeybars sits on JRuby, so you might be able to find some Java libraries to help you out along with your gems. A quick search for Java terminal stuff yielded JLine (http://jline.sourceforge.net/\). Of course, that's if the gem you had in mind isn't adequate for what you're doing.

···

On Jul 22, 2008, at 6:37 AM, James Dinkel wrote:

I have the same need. I have a script that runs in a terminal right
now, but I eventually want to make it gui (probably with Shoes) and I'll
need an option to click a button and open a command prompt (then run a
command in that command prompt and leave the prompt open for the user to
use).

I haven't even begun converting to the gui part yet though, so I haven't
put much thought into how I'm going to accomplish this. Oh yeah, and
this will need to be cross-platform, too, but it may just be a matter of
writing a slightly different program for each platform.

James
--
Posted via http://www.ruby-forum.com/\.

I don't think there's any standard way to open another terminal _window_,
given that some platforms allow you to install many different kinds of
terminals in the first place, and there simply is no way to do this
consistently and cross-platform.

On Windows, you could definitely call 'cmd'. On OS X, you're probably safe
doing something with Terminal.app. But on Linux, what do you do?
Gnome-terminal? Konsole? xterm? These are probably the most common to be
installed, yet none are guaranteed...

You could always implement your own terminal, in your own GUI -- but then
you'll irritate people who have a favorite terminal, and would rather work
from there. So this only really makes sense if you're just going to go
whole-hog and use the GUI for everything.

I think about all you can do here is detect that you're not running in a
terminal, and if you're not, exit with an error. Most platforms make it easy
enough to run a script in a terminal -- it's the default on Windows; OS X has
a "script menu" that opens them in Terminal; and on typical Linux desktop
environments, application launchers have a simple checkbox for "run in
terminal", and double-clicking on a Ruby script should run it in a terminal
anyway.

···

On Tuesday 22 July 2008 03:54:46 Sebastian Hungerecker wrote:

Tim Pease wrote:
> Kernel.exec '/bin/bash', '-c', "ruby #{__FILE__} #{ARGV.join(' ')}"

That won't open a terminal windows. It will simply execute bash which will
execute ruby, but if you weren't in a window before, you're still not.