code:-
import subprocess
print(subprocess.run(['date']))
when run it:-
Traceback (most recent call last):
File "D:\PyProjects\selenium\0experiment.py", line 8, in <module>
print(subprocess.run(['date']))
File "D:\Users\anaconda3\lib\subprocess.py", line 488, in run
with Popen(*popenargs, **kwargs) as process:
File "D:\Users\anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 104, in __init__
super(SubprocessPopen, self).__init__(*args, **kwargs)
File "D:\Users\anaconda3\lib\subprocess.py", line 800, in __init__
restore_signals, start_new_session)
File "D:\Users\anaconda3\lib\subprocess.py", line 1207, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
I am completely new to these and was learning these stuffs from online videos...in which tutor's same code ran flawlessly. Here is the video (at 1:40)
I also tried this code:
import subprocess
print(subprocess.run(['date'], shell=True))
But when ran, above code caused the console to run for long period of time and I have to terminate it manually (without printing anything on console). (WHY??)
I googled a lot and read a few somewhat similar type of question having such kind of Error...but not able to help myself: for example this thread.
What is this [WinError 2] , what causes this error?
FileNotFoundError , what file is this program referring to?
Is there any OS/system related prerequisites that needs to be fulfilled before programs using subprocess module can be executed?
I'm using windows 10, Spyder IDE(not installed in C drive but in D drive) having latest version of python.
Please explain in laymen terms. Thanks.
datemay be a Windows shell command so wouldn't be available withoutshell=True. If you just run "date" on Windows, I think it prompts for a new date to be entered. Does this course specify which operating system it uses? Try something known to be an executable (I think "find" is...?). If it works, write a note to coursera about their example.