open file on server with notepad via windows cmd in python -
i trying opne file located on server using windows cmd. following thing:
import os os.system('pushd '+ \\server\pathtofile) os.system('start notepad '+ nameoffile) the point works if enter hand in cmd. if try within python not work. error message:
cmd.exe started path given above current directory. unc-paths not supported, therefore windows-directory used current directory. the actual error message in german, that's why translated , i'm not sure whether it's understandable or not. happens path notepad looking current file c:\windows instead of path indicated.
windows doesn't support setting current directory unc path, , wouldn't have worked anyway since 2 separate os.system commands.
you mount drive on path , use os.chdir, make more complex yet!
you don't need current directory change. os.system deprecated, it's recommended use subprocess instead.
so change code run command providing full path file:
import subprocess subprocess.call(["start","notepad",os.path.join("\\server\pathtofile",nameoffile)],shell=true) but suspect you'd better off with
os.startfile(os.path.join("\\server\pathtofile",nameoffile)) (default associations of windows open "notepad" in background, that's one-line & simple, & users can change editor used changing text file association in windows)
Comments
Post a Comment