I am having a issue where the following line opens a cmd prompt and Sketchup immediately closes. There is no crash report or anything it simply disappears. Putting it in a begin rescue block does not seem to help. My python file only contains a infinite loop to keep the window from closing.
exec("python test.py params")
I want to run a python script from Ruby. Am I misunderstanding how this method works?
[Edit] system 'python test.py ' + params seems to work ok
But you must load the Open3 module from the standard library:
module Marsh
module Plugin
require "open3"
Open3.popen3(script) {
# code
}
end
end
The Open3 module is a double-duty library and mixin module. (There are 2 copies of each method, one for calling with qualification from outside, and an instance method copy for mixing into classes or modules, with include or extend. The example above shows that it has likely been included in a custom plugin class.)
Is there anyway I can execute popen3 without showing the terminal? Currently It pops a terminal window that starts post process script and closes when the script is done. I would prefer that this step is silent and not noticed by the user.
Not on Windows. It has been like this like forever. There is a bug (in the Ruby Core) that prevents us from using Cscript.exe (or Wscript.exe) as the shell because Ruby hardcodes adding a “/c” parameter (which assumes the command shell will always be cmd.exe.) That is plain stupid, when Ruby allows setting the RUBYSHELL environment variable.
Anyway if you change RUBYSHELL (for SketchUp’s copy of ENV,) you’ll get an error, because Microsoft stupidly wrote Cscript.exe (and Wscript.exe) to choke on unknown parameters, rather than ignore them like cmd.exe does. (Ie, they do not recognize a “/c” parameter.)
The simpliest workaround has been to write a one-line batch command file with Ruby, and then execute it silently using the SketchUp API’s UI.openURL() method.