Grasshopper-Python: How to start a CMD-Window and send commands to it with options

python

#1

Hi there.

Within GH via Python code I am trying to open a Command Prompt (Windows 7) and executing some commands in it.
The only thing I manage to do is just to open the CMD window and run a command without options like: “_Run C:/Windows/notepad.exe” or “_Run tasklist”
But any further options to that are ignored. So “_Run tasklist -v” or “_Run echo hello world” doesn’t work.
Can someone point me in the right direction what to do to get this working?
How to run several commands in a row in the same cmd window?

Thanks in advance.

cmd_runTest_2.gh (2.8 KB)


(Giulio Piacentino) #2

Hi @Tabak,

Space has a special meaning for the Rhino Command Line interface. You need to use double quotes to make the input exact.

Also, just look up examples of Python shell modules… os.system and subprocess.call:

from subprocess import call

file = r"C:\Users\test\test.py"
call(["cmd", "/K", "notepad.exe /A " + file + ""]) 

#https://ss64.com/nt/cmd.html
#https://answers.microsoft.com/en-us/windows/forum/windows_7-files/notepadexe-command-line-options/810760c1-a45a-4013-9544-1c1208e1b389

You may also start programs without the cmd command, this is only an example.

Thanks,

Giulio


Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com


#4

Thank you Giulio.
This made things clearer.