Escaping spaces in command line file paths

I am trying to run Rhino by passing it command line arguments, as detailed here: Rhino - Running Rhino from the Command Line

using the format:

“C:\Program Files\Rhinoceros 5 (64-bit)\System\Rhino.exe” /runscript=“commands here that also have a filepath in them” “J:\4_FORSCHUNG\F016_Screen Collection\04_COL_STUDIEN\151229_Animation in Rhino und GH\160106_Midi Animation 01.3dm”

As you can see I can escape the file path of the Rhino file to be opened by enclosing in “” as it has spaces in it. But that doesn’t work inside the /runscript part, as it is itself enclosed in “” and then assumes the runscript is already finished. Using ‘filepath’ and some other methods of escaping spaces don’t seem to be working.

So how can I pass a /runscript argument with a filepath with spaces?

Thanks for your help,


Look here:

In my case, I ended up with involving the shell object.


Thanks @Charles,

I just had another little look. So the -grasshopper command can open a file, but only accepts the filepath with " " around it if it contains spaces. That is the whole problem and in my opinion it shoulb be able to handle spaces if it only expects a filepath anyways.

So I am now just starting Rhino with a Pythonscript that then does all the necessary steps to do in Rhino using rs.Command like this:

C:\Program Files\Rhinoceros 5 (64-bit)\System\Rhino.exe /runscript="-RunPythonScript"

I am launching this from another scripting environment using ShellExecute.

The key was to escape the " that it needs to pass to the command. Its not very obvious because the command actually puts " " around the file path when it throws an error.

So here is the final format in Python:

ghFile = str(“C:\Users\path with spaces\”)

rs.Command(“Grasshopper”, True)
rs.Command("-grasshopper Document Open " + “”" + ghFile + “”", True)

I guess this is Windows’ limitation really, but also -grasshopper should be able to handle spaces in the filenames.

Ok, small update:

Just realised there is a much easier way to do this using scripting by using the actual Python Commands for Grasshopper, which can be found here:

That command can accept filepaths with spaces in it.

Well, I learned something though :wink:

There is a simple way to escape the colons in CMD commands which is to use double colons instead.
So, for example, to load python scripts which have spaces in the path you could use this:

"C:\Program Files\Rhino 6\System\Rhino.exe" /runscript="_-RunPythonScript ""C:\my path with spaces\my rhino"""  "C:\Projects\my rhino scene.3dm"

Thank you Albert :slight_smile: very helpful!