[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

On 03Jul2019 16:57, Jach Fong <jfong at> wrote:
>I have the below. I expect to see 'abcd' showing in the notepad window:
>import subprocess as sp
>p0 = sp.Popen('notepad.exe', stdin=sp.PIPE)
>But nothing happens. The notepad is completely empty. What have I missed?
>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.

Cameron Simpson <cs at>