How to pass string to executable stdin using in Python

In our previous example How to capture stdout to string using in Python we showcased how to use, out_stream=...) to capture stdout to a StringIO which can then be converted to a string.

Similarly, we can pass a string to the sub-process stdin by first converting it into a StringIO and then using, in_stream=...).

stdin_str = "abc123" # what we want to pass to stdint

stdin_io = StringIO(stdin_str)
result ="myexecutable", in_stream=stdin_in)
# ...