Last active
October 2, 2025 18:52
-
-
Save donutheist/07a81054218462f7bf182cf0ac394d82 to your computer and use it in GitHub Desktop.
Python pass input to to use as stdin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import subprocess | |
| def execute_command(command=None, stdin=None): | |
| proc = subprocess.Popen( | |
| command, | |
| stdin=subprocess.PIPE, | |
| stdout=subprocess.PIPE, | |
| stderr=subprocess.PIPE, | |
| text=True, | |
| ) | |
| # Use communicate to send input and capture both stdout/stderr | |
| stdout, stderr = proc.communicate(input=stdin) | |
| rc = proc.returncode | |
| return rc, stdout, stderr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment