Python Forum
subprocess error : The system cannot find the file specified
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
subprocess error : The system cannot find the file specified
#1
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:
    pass
but i keep got this error :
Error:
File "c:/Users/root/Desktop/testfunction.py", line 21, in <module> qassam = subprocess.Popen(["dir /s /b {}"]).format(lists[1]) File "C:\Python27\lib\subprocess.py", line 390, in __init__ errread, errwrite) File "C:\Python27\lib\subprocess.py", line 640, in _execute_child startupinfo) WindowsError: [Error 2] The system cannot find the file specified
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 :

Error:
C:\ Traceback (most recent call last): File "c:/Users/root/Desktop/testfunction.py", line 23, in <module> qassam = os.popen("dir /s /b %s").read() % lists[1] TypeError: not all arguments converted during string formatting

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 :
Error:
File "c:/Users/root/Desktop/testfunction.py", line 21, in <module> qassam = subprocess.Popen(["dir /s /b {}"]).format(lists[1]) File "C:\Python27\lib\subprocess.py", line 390, in __init__ errread, errwrite) File "C:\Python27\lib\subprocess.py", line 640, in _execute_child startupinfo) WindowsError: [Error 2] The system cannot find the file specified
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Absolute paths in subprocess - file not found kittyticker 4 406 Jan-28-2024, 10:37 PM
Last Post: kittyticker
  FileNotFoundError: [WinError 2] The system cannot find the file specified NewBiee 2 1,496 Jul-31-2023, 11:42 AM
Last Post: deanhystad
  Cannot find py credentials file standenman 5 1,572 Feb-25-2023, 08:30 PM
Last Post: Jeff900
  selenium can't find a file in my desk ? SouAmego22 0 702 Feb-14-2023, 03:21 PM
Last Post: SouAmego22
  Error when using FIND WJSwan 2 857 Jan-27-2023, 05:49 AM
Last Post: deanhystad
  Find (each) element from a list in a file tester_V 3 1,157 Nov-15-2022, 08:40 PM
Last Post: tester_V
  what will be the best way to find data in txt file? korenron 2 1,129 Jul-25-2022, 10:03 AM
Last Post: korenron
  find some word in text list file and a bit change to them RolanRoll 3 1,482 Jun-27-2022, 01:36 AM
Last Post: RolanRoll
  Find and delete above a certain line in text file cubangt 12 3,355 Mar-18-2022, 07:49 PM
Last Post: snippsat
  Error in find pearson correlation function erneelgupta 1 1,816 Mar-01-2022, 03:41 PM
Last Post: stevendaprano

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020