Opening a blend file through Command Line

Sorry, this might actually be a noob question but I’ve been stuck for hours now trying to figure this out.

I am trying to do the following with command prompt in windows

  • first, open blender,
  • open a particular blender file in that blender instance
  • and then run a python script.

I’ve followed the manual and it only works in a specific case.
What I mean is if I enter the following command “blender dir_of_blend_file” it works if the directory of the blend file has no space. for example something like this “D:\Documents\test.blend”. However, if the folder the blend file is saved on has spaces then I get some error in the console. Below is the console output

C:\Users\User>cd C:\Program Files\Blender Foundation\Blender 3.0

C:\Program Files\Blender Foundation\Blender 3.0>blender D:\Documents\dir with space\test.blend
Read prefs: C:\Users\User\AppData\Roaming\Blender Foundation\Blender\3.0\config\userpref.blend
Error: Cannot read file 'D:\Documents\dir': No such file or directory
Error: argument has no '.blend' file extension, not using as new file, exiting! D:\Documents\dir
Saved session recovery to 'C:\Users\User\AppData\Local\Temp\quit.blend'

Blender quit

C:\Program Files\Blender Foundation\Blender 3.0>

I feel there’s something rather obvious I don’t yet understand about cmd in windows so I’ll appreciate some direction on what to do to fix this. Thanks

P.S. What I’m originally trying to do is to create an independent python script that when run will open a particular blend file (using subprocess.Popen) and autorun a python script for that blender scene

1 Like

And just after posting the question, I figured it out. :sweat_smile:
spaces in cmd assume a new command. so if a directory has spaces then it must be enclosed in double quotes

4 Likes