简体   繁体   中英

Echoing the windows path in python

Essentially what I am trying to do is

from subprocess import call
print call(['echo', '%path%'])

however 'echo' is not recognized as an executable is there some kind of workaround?

I don't have a windows computer, but you could probably use os.environ to get it without relying on an external utility -- On *NIX it looks something like:

import os
print (os.environ['PATH'])

mgilson有更好的建议,但无论如何,仅供参考, echocmd.exe的内置命令:

subprocess.call("CMD /C ECHO %PATH%")

echo is not an executable, it is a shell command.

To execute shell commands, use:

subprocess.call("echo %PATH%", shell=True)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM