From 249bc245b9c52bd97df85e5fe69255d93fcd23f1 Mon Sep 17 00:00:00 2001 From: Sumanth Ratna Date: Sun, 20 Dec 2020 17:26:32 -0500 Subject: [PATCH] Only run ps -ww -p $PID -o command= if available --- better_exceptions/formatter.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/better_exceptions/formatter.py b/better_exceptions/formatter.py index c921cdd..c77a2c7 100644 --- a/better_exceptions/formatter.py +++ b/better_exceptions/formatter.py @@ -161,11 +161,16 @@ class ExceptionFormatter(object): pass if cmdline is None and os.name == 'posix': - from subprocess import CalledProcessError, check_output as spawn + from shutil import which - try: - cmdline = spawn(['ps', '-ww', '-p', str(os.getpid()), '-o', 'command=']) - except CalledProcessError: + if which('ps'): + from subprocess import CalledProcessError, check_output as spawn + + try: + cmdline = spawn(['ps', '-ww', '-p', str(os.getpid()), '-o', 'command=']) + except CalledProcessError: + return '' + else: return '' else: # current system doesn't have a way to get the command line