I want to execute another ruby script from my Shoes app. I try
我想从我的Shoes应用程序执行另一个ruby脚本。我试试
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?
一切正常。有任何想法吗?
5 个解决方案
#1
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.
事情正在发生,你只是没有对你的命令返回的文本做任何事情。当您通过'system'或反引号运行系统命令时,每个命令都会返回转储到STDOUT的命令。
Shoes.app do
@s = stack {}
button "go!" do
@out = `ls -al`
@s.clear { para @out }
end
end
#2
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.
这可能是奇怪的方式。但我认为有效。也许你使用Mac?(从您的路径),此代码适用于Windows。如果在Mac上,我认为你可以在执行终端后向终端发送命令。或者从ruby执行applescript。
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
#3
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
所以你可以看到它正在调用哪个ruby调用,并从那里开始工作
Even better, if open
is working, try changing your invocation of ruby
to /usr/bin/env ruby
.
更好的是,如果open工作正常,请尝试将ruby的调用更改为/ usr / bin / env ruby。
#4
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.
一个简单的要求怎么样?它确实有效,但是我可以想到没有什么可以追溯到之后真正发生的事情(除了真实的,如果一切都好的话还需要)...虽然系统在这种情况下不会提供更多的信息。
#5
load
may work better than
可能比工作更好
require
for you here. Require will only load something once.
对你来说要求只会加载一次。
#1
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.
事情正在发生,你只是没有对你的命令返回的文本做任何事情。当您通过'system'或反引号运行系统命令时,每个命令都会返回转储到STDOUT的命令。
Shoes.app do
@s = stack {}
button "go!" do
@out = `ls -al`
@s.clear { para @out }
end
end
#2
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.
这可能是奇怪的方式。但我认为有效。也许你使用Mac?(从您的路径),此代码适用于Windows。如果在Mac上,我认为你可以在执行终端后向终端发送命令。或者从ruby执行applescript。
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
#3
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
所以你可以看到它正在调用哪个ruby调用,并从那里开始工作
Even better, if open
is working, try changing your invocation of ruby
to /usr/bin/env ruby
.
更好的是,如果open工作正常,请尝试将ruby的调用更改为/ usr / bin / env ruby。
#4
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.
一个简单的要求怎么样?它确实有效,但是我可以想到没有什么可以追溯到之后真正发生的事情(除了真实的,如果一切都好的话还需要)...虽然系统在这种情况下不会提供更多的信息。
#5
load
may work better than
可能比工作更好
require
for you here. Require will only load something once.
对你来说要求只会加载一次。