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

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -