What's wrong on using Popen's communicate method?

jfong at ms4.hinet.net jfong at ms4.hinet.net
Thu Jul 4 00:38:47 EDT 2019


Wildman於 2019年7月4日星期四 UTC+8上午11時15分57秒寫道:
> On Thu, 04 Jul 2019 10:36:36 +1000, Cameron Simpson wrote:
> 
> > On 03Jul2019 16:57, Jach Fong <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
> > 
> > Well I am not a Windows person, but in most GUI environments a desktop 
> > app such as Notepad does not read from its standard input - it reads 
> > keyboard stuff though the GUI interface instead. So it is ignoring your 
> > input data - this approach will generally fail with any desktop app on 
> > any platform.
> > 
> > You may need to investigate generating synthetic keystrokes somehow.
> > 
> > Or alternatively write your data to a text file and hand the name of the 
> > text file to notepad as a file to edit.
> > 
> > Cheers,
> > Cameron Simpson <cs at cskk.id.au>
> 
> I block googlegroups so I don't see the original post.  I am
> talking to the OP.
> 
> Take a look at the SendKeys module.
> 
> https://pypi.org/project/SendKeys/
> 
> -- 
> <Wildman> GNU/Linux user #557453
> The cow died so I don't need your bull!

Thank you. But the download there seems is for Python 2.7?



More information about the Python-list mailing list