I am running a binary file that controls a USB device. The binary file, when executed, outputs the results to the file that I specify.
Is there any way in python to redirect the output of a binary to my script instead of a file? I just need to open the file and get it as soon as this line of code is launched.
def rn_to_file(comport=3, filename='test.bin', amount=128):
os.system('capture.exe {0} {1} {2}'.format(comport, filename, amount))
it does not work with the subprocess either
from subprocess import check_output as qx
>>> cmd = r'C:\repos\capture.exe 3 text.txt 128'
>>> output = qx(cmd)
Opening serial port \\.\COM3...OK
Closing serial port...OK
>>> output
b'TrueRNG Serial Port Capture Tool v1.2\r\n\r\nCapturing 128 bytes of data...Done'
The actual contents of the file are a series of 0 and 1. This is not a redirection of the output to the file to me, but simply prints out what will be printed anyway as output.
source
share