views:

854

answers:

5

Hi, everyone!

I want to execute another ruby script from my Shoes app. I try

button "..." do
  `ruby -rubygems /Users/kemiisto/Desktop/Ruby/gears.rb`  
end

but nothing happens. In the case of other commands, for example

button "..." do
  `open /Applications/TextEdit.app/`  
end

all works fine. Any ideas?

+1  A: 

Things are happening, you're just not doing anything with the text that your commands are returning. When you run a system command via 'system' or backticks each command returns whatever the command dumped to STDOUT.

Shoes.app do
  @s = stack {}

  button "go!" do
    @out = `ls -al`
    @s.clear { para @out }
  end
end
CJ Bryan
My script does not return any text. It is simple OpenGl Demo script.
A: 

I'd try running

    Shoes.app do
  @s = stack {}
  button "debug" { @s.clear { para `which ruby` } }
 end

so you can see which invocation of ruby it's calling, and work from there

Even better, if open is working, try changing your invocation of ruby to /usr/bin/env ruby.

rampion
At first I thought that the usage of full path is solution. I try /usr/local/bin/ruby instead of ruby. It works from terminal as before, but not from Shoes app. (((
A: 

How about a simple require? It definitely works, but I can think of nothing to trace back what's really going on after (apart from the true, returned by require if everything is alright)... Although system wouldn't be much more informative in this scenario.

A: 
load

may work better than

require

for you here. Require will only load something once.

toothrot
A: 

This is maybe strange way. But I think works.
Maybe you use Mac ?(from your path),This code works in windows.
If on Mac, I think you can send command to terminal after execute terminal.
or execute applescript from ruby.

Hope this below idea help you(for win).

require 'win32ole'

...some code...

button "..." do
  @auto = WIN32OLE.new('AutoItX3.Control')
  @auto.Run('cmd.exe','',@SW_MAXIMIZE)
  @auto.WinActivate("C:\WINDOWS\system32\cmd.exe")
  @auto.ControlSend("[CLASS:ConsoleWindowClass]", "", "", 'ruby -rubygems /Users/kemiisto/Desktop/Ruby/gears.rb')
end
tknv