python - subprocess.Popen and relative directories -
i writing script open notepad.exe using subprocess.popen()
import subprocess command = '%windir%\system32\\notepad.exe' process = subprocess.popen(command) output = process.communicate() print(output[0])
this throws filenotfounderror
is possible change/add above code make work relative paths? did try run script c:\windows> after moving there, again failed. set shell=true, failed well. writing similar script using os.popen() works ok relative paths, regardless directory script run from, far understand popen not way forward..
early steps in world of programming/python. input appreciated.
use os.path.expandvars
expand %windir%
:
command = os.path.expandvars('%windir%\\system32\\notepad.exe')
the result path can passed subprocess.popen
.
subprocess.popen
not expand environment variables such %windir%
. shell might should not depend on shell=true
that.
Comments
Post a Comment