What I want though is to run a program and log both the stdin and stdout, but I want the stdin to be supplied from a file.I thought script log.txt < input.txt would work, but it does not, because the stdin does not get logged, only the output gets logged.Where input.txt is./programsomething for the stdin of programsome more stuff
Log both stdin and stdout of program
bash;logs;io redirection
I ended up hacking this thing together:import subprocessimport timeimport syslog = open(sys.argv[3], 'w')input = open(sys.argv[2], 'r')p = subprocess.Popen([sys.argv[1]], stdin=subprocess.PIPE, stdout=subprocess.PIPE)def readAllSoFar(proc, retVal=''):  while (subprocess.select.select([proc.stdout],[],[],0)[0]!=[]):    retVal+=proc.stdout.read(1)  return retValwhile True:    print('starting loop')    line = input.readline()    print('read line ' + line)    if not line:        print('breaking')        break    print('before sleep1')    time.sleep(0.1)    print('before readAllSoFar')    output = readAllSoFar(p)    print('got output' + output)    log.write(output)    time.sleep(0.1)    log.write(line)    p.stdin.write(line)Run it with python runner.py ./program_to_run input.txt output.txtIt assumes any output from a command will be done in a tenth of a second.