formatting strings for stdin.write() in python 3.x

Is your error message "TypeError: 'str' does not support the buffer interface"? That error message tells you pretty much exactly what is wrong. You don't write string objects to that sdtin. So what do you write? Well, anything supporting the buffer interface. Typically this is bytes objects.

Like:

working_file.stdin.write(b'message')

If you have a string variable that you want to write to a pipe (and not a bytes object), you have two choices:

  1. Encode the string first before you write it to the pipe:
working_file.stdin.write('message'.encode('utf-8'))
  1. Wrap the pipe into a buffered text interface that will do the encoding:
stdin_wrapper = io.TextIOWrapper(working_file.stdin, 'utf-8')
stdin_wrapper.write('message')

(Notice that the I/O is now buffered, so you may need to call stdin_wrapper.flush().)