Invoke a third-party command-line tool with arguments from GHPython?

Hi,

I’m trying to run a shell command with arguments (i.e. cmd = "tool -i -o -e "file.txt") from GHPython in Rhino 6 for Mac to post-process some files! tool is a third-part command-line tool.

I’ve tried os.system(cmd) which works for rudimentary bash commands, but doesn’t seem to be able to call a third-party command-line tool, like it does on Windows? Since it doesn’t output anything useful (prints 1?), not even an error, it’s hard to debug. On Windows, a command prompt window launches and the command runs! On macOS, nothing happens?

I’ve also tried the subprocess library without much luck!
Only very few functions are even implemented in the terrible and dated IronPython.
subprocess.call(shlex.split(cmd)) throws a Win32Exception (and that on macOS, I don’t even dare to ask)? By the way, shlex.split() well splits my command string into a list of strings for subprocess.call(), which likes it that way.

Runtime error (Win32Exception): Runtime error (Win32Exception): ApplicationName=‘tool’, CommandLine=‘-i -o -e file.txt’, CurrentDirectory=‘/Users/*****/Desktop/’, Native error= Cannot find the specified file

I have tested the command in macOS Terminal (unix shell) and it runs fine. The tool is properly installed. The text file sits in the right location and I os.chdir() to the right path beforehand!

Again, I’m trying to invoke a third-party command-line tool with arguments that then runs inside a shell (not Rhino/Grasshopper) and post-processes a file that get’s output beforehand by Rhino. GHPython just needs to launch the shell and communicate the command string! It would be cool, if a command output could be send back to GHPython for debugging, but I’m already more than happy, if I get the first part running!

Any ideas? Thanks.

Hi @diff-arch, i used subprocess.Popen successfully under Windows. It allows to poll the process, can read stdout and stderr from the command line app while it is running and you can get return code to detect if things are done. Setting up the cmd part has been a bit of a hassle but maybe you can try it on mac.

_
c.

1 Like