subprocess error : The system cannot find the file specified - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: subprocess error : The system cannot find the file specified (/thread-13188.html) |
subprocess error : The system cannot find the file specified - evilcode1 - Oct-03-2018 hey all ... i writing a code to check the windows titles and look for browser google if he found it take a variable from list and run this command on system to bring the full dir for the chrome browser ... this is my code : import os import subprocess home = os.environ.get("HOMEDRIVE") lol =home +"/" #mycurrent = os.getcwd() #change = os.chdir(lol) proc = os.popen("""for /f "tokens=3,*" %a in ('tasklist /fo list /v ^| find "Window Title"') do @if not "%a"=="N/A" echo %a %b""").read().splitlines() d = os.popen("""wmic process get name | findstr /v "Name 'System Idle Process' System""").read().lower() #print proc lists = ["opera.exe" , "chrome.exe" , "iexplore.exe" , "firefox.exe" , "microsoftedgecp.exe"] if any("Google Chrome" in s for s in proc) and lists[1] in d : #home = os.environ.get("HOMEDRIVE") #lol =home +"/" mycurrent = os.getcwd() change = os.chdir(lol) mycurrent = os.getcwd() print mycurrent qassam = subprocess.Popen(["dir /s /b {}"]).format(lists[1]) #qassam = subprocess.Popen(["dir /s", "/b {}"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT).format(lists) else: passbut i keep got this error : i try with this 3 methods :1- qassam = subprocess.Popen(["dir /s /b {}"]).format(lists[1]) 2- qassam = subprocess.Popen(["dir /s", "/b {}"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT).format(lists) 3- qassam = os.popen("dir /s /b %s").read() % lists[1] when i try with the third method i got this error :
solved .. From my stupidity I forgot to but .format inside () i change it from : qassam = os.popen("dir /s /b %s").read() % lists[1] to : qassam = os.popen("dir /s /b {}".format(lists[1])).read() but i still face this error when i use subporcess :
|