From ff2d609c9b5f5f57f3331e5593e8fe87c01654dd Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Thu, 12 Aug 2021 16:36:35 -0700 Subject: [PATCH] add close_fds=False in subprocess.Popen() to allow process substitution in magic syntax. Also check for too many open files exception --- jc/cli.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/jc/cli.py b/jc/cli.py index 4dafde69..a756eb91 100644 --- a/jc/cli.py +++ b/jc/cli.py @@ -466,7 +466,11 @@ def magic_parser(args): def run_user_command(command): """Use subprocess to run the user's command. Returns the STDOUT, STDERR, and the Exit Code as a tuple.""" - proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) + proc = subprocess.Popen(command, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + close_fds=False, + universal_newlines=True) stdout, stderr = proc.communicate() return ( @@ -560,6 +564,13 @@ def main(): jc.utils.error_message(f'"{run_command_str}" command could not be found. For details use the -d or -dd option.') sys.exit(combined_exit_code(magic_exit_code, JC_ERROR_EXIT)) + except OSError: + if debug: + raise + else: + jc.utils.error_message(f'"{run_command_str}" command could not be run due to too many open files. For details use the -d or -dd option.') + sys.exit(combined_exit_code(magic_exit_code, JC_ERROR_EXIT)) + except Exception: if debug: raise