kemiisto
kemiisto

Reputation:

How to execute ruby script on some event?

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?

Upvotes: 2

Views: 1863

Answers (5)

tknv
tknv

Reputation: 562

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

Upvotes: 1

toothrot
toothrot

Reputation: 126

load

may work better than

require

for you here. Require will only load something once.

Upvotes: 0

georgils
georgils

Reputation:

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.

Upvotes: 0

rampion
rampion

Reputation: 89093

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.

Upvotes: 0

CJ Bryan
CJ Bryan

Reputation: 178

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

Upvotes: 2

Related Questions