I'm working on a terminal that can call other programs like any other terminal. I'm using subprocess for it, on Windows. I'm running into 2 issues.
First: Currently, I'm using OSError for all errors raised when using subprocess.Popen.
The code for it is here:
try:
subprocess.Popen([command])
except OSError:
print("'" + command[0] + "' is not recognised as a command, program or bterm file.")
When I type python
, it opens command-line python correctly.
When I type asdfa
, it returns the error.
The problem is, when I type python non-existent-file.py
I get the same error, when the child argument was the issue.
I want the terminal to return (null): can't open file 'test': [Errno 2] No such file or directory
like when it's called from cmd or bash.
How can I distinguish between these 2 errors, while keeping my custom error message for when the file doesn't exist?
Second: Whenever I pass multi-word args into subprocess.Popen
or subprocess.call
I automatically get that error, which I don't get using os.system()
I don't want to use os.system
because I can't raise custom errors with it.
What am I doing wrong?