1

In python if I try to give path with space I'm getting error as below

import os  
os.system("C:\Program Files (x86)\(application.exe)")

'C:\Program' is not recognized as an internal or external command, operable program or batch file.

How can I give path with space?

1 Answer 1

11

You can make it working by using r.

E.g. :

import os
cmd =r'"C:\Program Files (x86)\Java\jre7\bin\java.exe"'
os.system(cmd)
Sign up to request clarification or add additional context in comments.

3 Comments

You don't need the r, just the double quotation ('"..."'). This passes a quoted string to the OS, which it needs to deal with the space.
in my case double quotes is not working, but this solution works.
No, I mean ' + ". The outer set of ' for Python means "send this string (including the double quotes ") to the shell

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.