I am using subprocess in python 3 to use operating system commands (I am on ubuntu 18.04) and I was wondering if there was anyway to make make a custom error message while shell=True
import subprocess
command = str('wrong')
try:
grepOut = subprocess.check_output(command, shell=True)
except subprocess.CalledProcessError as grepexc:
print("oops! wrong command")
When i run it I get:
/bin/sh: 1: wrong: not found
oops! wrong command
is there any way to remove the "/bin/sh: 1: wrong: not found" message and just have "oops! wrong command"?