"mode" doesn't run in python 3.5 subprocess -
i have encountered bit of conundrum while working on automation project.
when try run:
program = subprocess.run("mode") i get:
filenotfounderror: [winerror 2] system cannot find file specified however, when replace mode ipconfig:
program = subprocess.run("ipconfig") it runs fine.
anyone got explanation? using batch file run mode command, change arguments without editing batch file.
edit 1:
i tried using os.system:
os.system("mode") and worked.
edit 2:
now answer original problem understand going on.
in actual meaning of 'shell=true' in subprocess pretty says shell=true should shy away from.
filenotfounderror: [winerror 2] system cannot find file specified is tipped me off might want shell=true in subprocess call. if file can't found means 1 of 2 things:
- it's not on path.
- it's not actually file.
for instance, in linux:
$ echo echo: shell built-in command that makes pretty obvious there is no echo file. it's command that's built shell. may same thing when comes mode on windows. though this site seems suggest it's mode.com file. may try invoking that, in
subprocess.run('mode.com') that may work - @ least according 1 of the answers linked to
invoking via shell allow expand environment variables , file globs according shell's usual mechanism. on posix systems, shell expands file globs list of files. on windows, file glob (e.g., ".") not expanded shell, anyway (but environment variables on command line expanded cmd.exe).
so in case, perhaps mode isn't file, mode.com is, , since windows has spotty relationship casing, seems possible passing shell=true, windows shell happily takes mode , converts mode.com you, without it, tries execute file literally named mode, doesn't exist.
Comments
Post a Comment