What's wrong on using Popen's communicate method?
Terry Reedy
tjreedy at udel.edu
Thu Jul 4 12:12:57 EDT 2019
On 7/3/2019 7:57 PM, jfong at ms4.hinet.net wrote:
> I have the test0.py below. I expect to see 'abcd' showing in the notepad window:
> ---------
> import subprocess as sp
> p0 = sp.Popen('notepad.exe', stdin=sp.PIPE)
> p0.communicate(input=b'abcd')
> ---------
> But nothing happens. The notepad is completely empty. What have I missed?
>
> --Jach
>
> PS. I am using python 3.4 on Windows Vista
Upgrade to 3.7 or 3.8 to get hundreds of bug fixes, let alone new
features. Both subprocess and multiprocessing have gotten fixes.
subprocess is meant for running an external program in batch mode. It
receives the one input byte string, sends output, and closes. For
interaction, try multiprocessing.
Or do what IDLE does, which is to open a two-way socket to the parent
program. (Managing this is not fun.) IDLE was initially written before
multiprocessing. It has been suggested to me that it should switch to
multiprocessing. (But last I read, multiprocessing and tkinter (tcl/tk)
do not play well together on macOS.)
If the subprocess runs a gui, the user should be able to switch focus by
clicking on a subprocess window.
--
Terry Jan Reedy
More information about the Python-list
mailing list