# Print out the command line arguments list elements. # Add the above windows executable file path to the command line arguments list.Ĭmd_param_arrray.append(cmd_executeable_file_path) # Get the windows executable file ( notepad.exe ) path.Ĭmd_executeable_file_path = os.path.join(win_dir_path, 'notepad.exe') Win_dir_path = os.environ "\\System32\\" # Create the windows executable file command line arguments array. # This function will call the python subprocess module's Popen method to invoke a system executable program. I use the python subprocess module’s Popen function to execute a windows executable program like below, and it throws the FileNotFoundError.2.1 The FileNotFoundError: Occurred When Use Python Subprocess Module’s Popen() Method. The subprocess module’s run method returns an instance of the subprocess.CompletedProcess class, this object records the completed process status data (ie: executed command, return code, etc.) 2.> ret = n(, shell=True)ĬompletedProcess(args=, returncode=0) After I add the shell=True argument in the subprocess module’s run method, it runs successfully like below.This error is because I run the above command in a window shell, but do not specify the shell=True argument in the subprocess module’s run method.With Popen(*popenargs, **kwargs) as process:įile "C:\Users\zhaosong\anaconda3\envs\env_python_37\lib\subprocess.py", line 800, in _init_įile "C:\Users\zhaosong\anaconda3\envs\env_python_37\lib\subprocess.py", line 1207, in _execute_childįileNotFoundError: The system cannot find the file specified > import subprocessįile "C:\Users\zhaosong\anaconda3\envs\env_python_37\lib\subprocess.py", line 488, in run Below is the detailed error message and the steps to reproduce it.The FileNotFoundError: The System Cannot Find The File Specified. Or in this simple case just: subprocess.1. In these cases i strongly recommend the usage of the shlex module: import shlex Most subprocess-commands expect the shellcmd to be submitted as a list of strings. The problem is simply that the call to subprocess.call('py.test') is failing.įor future reference, this is the type of traceback you encounter when attempting to import a module that has not been installed: > import foo That traceback indicates that subprocess is installed and has been imported. Likely the executable file that you are attempting to call Popen on cannot be found. The error that you show in your question update is nothing more prosaic than a file not found error. The documentation shows that it was added to the library for Python version 2.4. It is a standard module that is built in. There is no need to install this module in Python 2.7.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |