How to open a console and ruby a ruby script from ruby?

I know I can do

  system "ruby script.rb"

But I want to open a console to run it in.

Thanks.
T

you mean a pty? check out ext/pty, there's an example in there.

cheers.

-a

···

On Sun, 2 Jul 2006 transfire@gmail.com wrote:

I know I can do

system "ruby script.rb"

But I want to open a console to run it in.

--
suffering increases your inner strength. also, the wishing for suffering
makes the suffering disappear.
- h.h. the 14th dali lama

I want a window to come up with a shell propmt (or dos on windows).

T.

···

ara.t.how...@noaa.gov wrote:

On Sun, 2 Jul 2006 transfire@gmail.com wrote:

> I know I can do
>
> system "ruby script.rb"
>
> But I want to open a console to run it in.

you mean a pty? check out ext/pty, there's an example in there.

you probably want something like

   fortytwo :~ > cat a.rb
   require 'rbconfig'
   require 'tempfile'

   def console command
     arch = Config::CONFIG['arch']

     unless arch =~ %r/win/i
       tmp = Tempfile.new Process.pid.to_s
       tmp << command
       tmp << "\n"
       tmp << "bash"
       tmp << "\n"
       tmp.close
       begin
         system "xterm -e 'bash -l -i #{ tmp.path }'"
       ensure
         tmp.close!
       end
     else
       raise 'windoze'
     end
   end

   console 'date'

i'll leave the windoze bit to you :wink:

regards.

-a

···

On Sun, 2 Jul 2006 transfire@gmail.com wrote:

ara.t.how...@noaa.gov wrote:

On Sun, 2 Jul 2006 transfire@gmail.com wrote:

I know I can do

system "ruby script.rb"

But I want to open a console to run it in.

you mean a pty? check out ext/pty, there's an example in there.

I want a window to come up with a shell propmt (or dos on windows).

--
suffering increases your inner strength. also, the wishing for suffering
makes the suffering disappear.
- h.h. the 14th dali lama

Thanks. It worked!!!! Check out Ballyhoo balloon :wink:

T.

···

ara.t.howard@noaa.gov wrote:

On Sun, 2 Jul 2006 transfire@gmail.com wrote:

>
> ara.t.how...@noaa.gov wrote:
>> On Sun, 2 Jul 2006 transfire@gmail.com wrote:
>>
>>> I know I can do
>>>
>>> system "ruby script.rb"
>>>
>>> But I want to open a console to run it in.
>>
>> you mean a pty? check out ext/pty, there's an example in there.
>
> I want a window to come up with a shell propmt (or dos on windows).

you probably want something like

Windoze equivalent inserted below :slight_smile:

   fortytwo :~ > cat a.rb
   require 'rbconfig'
   require 'tempfile'

   def console command
     arch = Config::CONFIG['arch']

     unless arch =~ %r/win/i
       tmp = Tempfile.new Process.pid.to_s
       tmp << command
       tmp << "\n"
       tmp << "bash"
       tmp << "\n"
       tmp.close
       begin
         system "xterm -e 'bash -l -i #{ tmp.path }'"
       ensure
         tmp.close!
       end
     else

          system "start cmd /k #{command}"

     end
   end

   console 'date'

Regards,
Sean

···

On 7/1/06, ara.t.howard@noaa.gov <ara.t.howard@noaa.gov> wrote:

Beware that you're technically detecting both windows and mac (darwin)
with /win/. You might want to check for win32 (or, i suppose, win64?)
instead.

- james

···

On 7/2/06, Sean O'Halpin <sean.ohalpin@gmail.com> wrote:

Windoze equivalent inserted below :slight_smile:

On 7/1/06, ara.t.howard@noaa.gov <ara.t.howard@noaa.gov> wrote:
>
> fortytwo :~ > cat a.rb
> require 'rbconfig'
> require 'tempfile'
>
> def console command
> arch = Config::CONFIG['arch']
>
> unless arch =~ %r/win/i
> tmp = Tempfile.new Process.pid.to_s
> tmp << command
> tmp << "\n"
> tmp << "bash"
> tmp << "\n"
> tmp.close
> begin
> system "xterm -e 'bash -l -i #{ tmp.path }'"
> ensure
> tmp.close!
> end
> else
          system "start cmd /k #{command}"
> end
> end
>
> console 'date'
>

Regards,
Sean

--
* J *
  ~

James Adam wrote:

Beware that you're technically detecting both windows and mac (darwin)
with /win/. You might want to check for win32 (or, i suppose, win64?)
instead.

Thanks. I'll change that. How does one do this on mac btw?

T.

the xterm command should work fine.

-a

···

On Mon, 3 Jul 2006 transfire@gmail.com wrote:

James Adam wrote:

Beware that you're technically detecting both windows and mac (darwin)
with /win/. You might want to check for win32 (or, i suppose, win64?)
instead.

Thanks. I'll change that. How does one do this on mac btw?

T.

--
suffering increases your inner strength. also, the wishing for suffering
makes the suffering disappear.
- h.h. the 14th dali lama

Eh, yeah but it's not ideal (You'll have to wait for X11 to start usually, which it may or may not do automatically, I'm not sure. i think it might if opened via the Finder but not from the command line).

What I would do is

IO.popen("osascript", "w") do |io|
    io.puts <<APPLESCRIPT
tell Application "Terminal"
   activate
   do script "#{command_here}"
end tell
APPLESCRIPT
end

This has the advantage of not opening a new instance of terminal if one is already open, (but it will if necessary) and not requiring the user to a) have X11 installed and b) have it running.

···

On Jul 2, 2006, at 2:02 PM, ara.t.howard@noaa.gov wrote:

On Mon, 3 Jul 2006 transfire@gmail.com wrote:

James Adam wrote:

Beware that you're technically detecting both windows and mac (darwin)
with /win/. You might want to check for win32 (or, i suppose, win64?)
instead.

Thanks. I'll change that. How does one do this on mac btw?

T.

the xterm command should work fine.

-a
--
suffering increases your inner strength. also, the wishing for suffering
makes the suffering disappear.
- h.h. the 14th dali lama

Logan Capaldo wrote:

Eh, yeah but it's not ideal (You'll have to wait for X11 to start
usually, which it may or may not do automatically, I'm not sure. i
think it might if opened via the Finder but not from the command
line).

What I would do is

IO.popen("osascript", "w") do |io|
    io.puts <<APPLESCRIPT
tell Application "Terminal"
   activate
   do script "#{command_here}"
end tell
APPLESCRIPT
end

This has the advantage of not opening a new instance of terminal if
one is already open, (but it will if necessary) and not requiring the
user to a) have X11 installed and b) have it running.

Thanks. I added it to my balloon. Maybe it works?

  http://balloon.hobix.com/ballyhoo

T.

Well, it doesn't work but not because of terminals not opening. You have a syntax error in the actual page

io.puts << APPLESCRIPT

should be

io.puts <<APPLESCRIPT # it's a heredoc

···

On Jul 2, 2006, at 2:45 PM, transfire@gmail.com wrote:

Logan Capaldo wrote:

Eh, yeah but it's not ideal (You'll have to wait for X11 to start
usually, which it may or may not do automatically, I'm not sure. i
think it might if opened via the Finder but not from the command
line).

What I would do is

IO.popen("osascript", "w") do |io|
    io.puts <<APPLESCRIPT
tell Application "Terminal"
   activate
   do script "#{command_here}"
end tell
APPLESCRIPT
end

This has the advantage of not opening a new instance of terminal if
one is already open, (but it will if necessary) and not requiring the
user to a) have X11 installed and b) have it running.

Thanks. I added it to my balloon. Maybe it works?

  http://balloon.hobix.com/ballyhoo

T.