So how do I pass binary data using stdin to a executable command that I want to run using subprocess.run()?
The documentation is pretty vague about using the stdin for passing the data to external executable. I'm working on linux machine using python3 and I want to invoke dd of=/somefile.data bs=32 (which takes the input from stdin if I understand the man page correctly) and I have the binary data in bytearray that I want to pass to the command through stdin so that I do not have to write it to a temporary file and invoke the dd using that file as a input.
My requirement is simply to pass data that I have in bytearray to the dd command to be written to disk. What is the correct way to achieve this using the subprocess.run() and stdin?
Edit: I meant something like the following:
ba = bytearray(b"some bytes here")
#Run the dd command and pass the data from ba variable to its stdin
stdin=<something>when usingPopen, but not sure you can set it to be just stdin, you need to gather your input first, then pass it to the subprocess. If you have another process generating output that you want to use asstdinhere you can certainly do that though - i.e. stdin for proc2 is output from proc1. SO proc1 would be yourddcommand, and proc2 would be whatever process you want to pass the output to. Not sure if this helps - I'm a little unclear as to the exact requirement here.bytearrayto theddcommand to be written to disk. Editing the question.