Ruby system call
-
Does the system function work in SketchUp Ruby?
Any tips on how to use it?
I am passing in two args, the full path to a .exe file (cmd), and the full path to a file I want the executable to process (file). I get nothing.
I also tried (UI.messagebox
cmd file
, using the backtick syntax, but it interpreted the arguments literally, saying:Error: #<Errno::ENOENT: No such file or directory - cmd file>
Do I need to use some special quoting technique?
Thanks,
Jeff -
What's the full path to the file you try to execute? Does it contain non-ASCII characters by any chance?
-
I'm not sure about your system call question. But if you want to display the cmd file variables correctly inside the messagebox, try it without the quotes and it will evaluate the variables, instead of printing the variable name
UI.messagebox cmd + file
or, if you wanted to display them inside a string, do it like this:
UI.messagebox "I am trying to run this file: #{cmd+file} and I hope it works eventually!"
the
#{ }
syntax will evaluate whatever is inside the braces when they inside a string (must use double quotes " instead of single quotes ' around the string from what I understand. You can even call a method and run regular code inside the braces, like this:` def my_method
cmd = "the path"
file = "filename"
cmd+path
endUI.messagebox "This is the path #{my_method}."`
And that should work too.
But it doesn't answer the question that you had I think.....sorry.
Chris
-
Tom,
To set the command path, I use the $: system variable to get a path to the Plugins directory, and then tack on the rest of the path to the executable. No special characters. Before doing the system call, I print out both the cmd and file strings, and they look correct.
Jim,
The backquotes I am using are supposed to run the command in the quotes, and return the command output as a string. I wanted that returned string to go to a messagebox, which it did... the error message I showed in my original post.
Thanks for the help.
Any more suggestions? -
-
Yes, that works. Thanks Jim.
Advertisement