Codebase list python-procrunner / 76cbd98
Allow stdin=subprocess.DEVNULL The current default is to connect through the existing stdin to the subprocess, and there is no way to explicitly close the subprocess stdin. Allow stdin=subprocess.DEVNULL for this. (Backport from v3.0) Markus Gerstel 2 years ago
3 changed file(s) with 26 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
00 =======
11 History
22 =======
3
4 2.3.2 (2022-01-28)
5 ------------------
6 * The run() function now understands stdin=subprocess.DEVNULL to close the subprocess stdin,
7 rather than to connect through the existing stdin, which is the current default
38
49 2.3.1 (2021-10-25)
510 ------------------
454454 :param array command: Command line to be run, specified as array.
455455 :param timeout: Terminate program execution after this many seconds.
456456 :param boolean debug: Enable further debug messages. (deprecated)
457 :param stdin: Optional bytestring that is passed to command stdin.
457 :param stdin: Optional bytestring that is passed to command stdin,
458 or subprocess.DEVNULL to disable stdin.
458459 :param boolean print_stdout: Pass stdout through to sys.stdout.
459460 :param boolean print_stderr: Pass stderr through to sys.stderr.
460461 :param callback_stdout: Optional function which is called for each
484485
485486 if stdin is None:
486487 stdin_pipe = None
488 elif isinstance(stdin, int):
489 assert (
490 stdin == subprocess.DEVNULL
491 ), "stdin argument only allows subprocess.DEVNULL as numeric argument"
492 stdin_pipe = subprocess.DEVNULL
493 stdin = None
487494 else:
488495 assert sys.platform != "win32", "stdin argument not supported on Windows"
489496 stdin_pipe = subprocess.PIPE
1414 command = ["echo", "hello"]
1515
1616 result = procrunner.run(command)
17
18 assert result.returncode == 0
19 assert result.stdout == b"hello" + os.linesep.encode("utf-8")
20 assert result.stderr == b""
21
22
23 def test_simple_command_invocation_with_closed_stdin():
24 if os.name == "nt":
25 command = ["cmd.exe", "/c", "echo", "hello"]
26 else:
27 command = ["echo", "hello"]
28
29 result = procrunner.run(command, stdin=subprocess.DEVNULL)
1730
1831 assert result.returncode == 0
1932 assert result.stdout == b"hello" + os.linesep.encode("utf-8")