Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_cli_output(self, args, get_stderr=False):
argv_in, stdout_in, stderr_in = sys.argv, sys.stdout, sys.stderr
sys.argv = args
sys.stdout = StringIO()
sys.stderr = StringIO()
try:
f90nml.cli.parse()
except SystemExit:
pass
sys.stdout.seek(0)
stdout = sys.stdout.read()
sys.stdout.close()
sys.stderr.seek(0)
stderr = sys.stderr.read()
sys.stderr.close()
sys.argv, sys.stdout, sys.stderr = argv_in, stdout_in, stderr_in
# TODO: Some way to check both would be more useful...
if get_stderr:
return stderr