Reputation: 613
Let's say I have a network path like this below:
\\srv\teams\dir 1
How can I open it using subprocess? I am trying:
subprocess.Popen("explorer '\\srv\teams\dir 1'")
but it always leads me to my 'My Documents'. It works fine from cmd. I am using win7.
I also tried:
os.system("explorer '\\srv\teams\dir 1'")
Upvotes: 0
Views: 577
Reputation: 40763
Please see Mike Scotty for solution regarding os.system. If you use subprocess
, please use a list of string for your command instead of a single string:
subprocess.call(['explorer', '\\\\srv\\teams\\dir 1'])
Note that I use subprocess.call
instead of subprocess.Popen
since this is a simple call, no need to overkill
Upvotes: 1
Reputation: 10782
There are two issues with your code:
1) Use a raw string or escape your \
characters
2) Use "
instead of '
to enclose the path
os.system(r'explorer "\\srv\teams\dir 1"')
Upvotes: 1