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

2019-07-07 Thread jfong
eryk sun於 2019年7月7日星期日 UTC+8下午3時51分57秒寫道:
> On 7/6/19, jf...@ms4.hinet.net  wrote:
> >
> > I turn off the anti-virus and tried v3.6.8, get the same result. Usually the
> > anti-virus program will warn me if something was blocked.
> 
> In case the executable is corrupt, clear your browser cache and
> download the 32-bit version again:
> 
> https://www.python.org/ftp/python/3.6.8/python-3.6.8.exe
> 
> Try to run the installer from an elevated command prompt. If it fails
> to run, check again for log files in your %TEMP% directory, which
> typically expands to "C:\Users\\AppData\Local\Temp".
> 
> If the installer is still not running -- not even enough to create a
> single log file -- then apparently something is configured incorrectly
> or missing on your computer that's causing it to fail hard. I'd have
> to run it under a debugger to find the cause.
> 
> Anyway, if you're stuck with ancient 3.4, you can at least install
> "pywin32-221.win32-py3.4.exe" from the old SourceForge repo:
> 
> https://sourceforge.net/projects/pywin32/files/pywin32/Build%20221

I had overlooked your suggestion of installing it under elevated command 
prompt. At the last moment I was noticed and gave it a try. Guess what? I run 
Python-3.6.8.exe successfully and installed it. A real surprise!

Thank you for everything you had done to help.

--Jach
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2019-07-07 Thread jfong
eryk sun於 2019年7月7日星期日 UTC+8下午3時51分57秒寫道:
> On 7/6/19, jf...@ms4.hinet.net  wrote:
> >
> > I turn off the anti-virus and tried v3.6.8, get the same result. Usually the
> > anti-virus program will warn me if something was blocked.
> 
> In case the executable is corrupt, clear your browser cache and
> download the 32-bit version again:

I have its MD5 checked after each download.
 
> https://www.python.org/ftp/python/3.6.8/python-3.6.8.exe
>
> Try to run the installer from an elevated command prompt. If it fails
> to run, check again for log files in your %TEMP% directory, which
> typically expands to "C:\Users\\AppData\Local\Temp".
> 
> If the installer is still not running -- not even enough to create a
> single log file -- then apparently something is configured incorrectly
> or missing on your computer that's causing it to fail hard. I'd have
> to run it under a debugger to find the cause.

It's very possible there is some problem in my system. A few months ago  
suddenly I can't login to my email account through ThunderBird. Now I have to 
remove my password from its settings and manually type-in every time when I log 
in.

Using a debugger is a big burden to me because I am not familiar with the 
internal of Windows well.

> Anyway, if you're stuck with ancient 3.4, you can at least install
> "pywin32-221.win32-py3.4.exe" from the old SourceForge repo:
> 
> https://sourceforge.net/projects/pywin32/files/pywin32/Build%20221

Thank you for the link. I will try it later and hope it will run:-)

--Jach
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2019-07-07 Thread eryk sun
On 7/6/19, jf...@ms4.hinet.net  wrote:
>
> I turn off the anti-virus and tried v3.6.8, get the same result. Usually the
> anti-virus program will warn me if something was blocked.

In case the executable is corrupt, clear your browser cache and
download the 32-bit version again:

https://www.python.org/ftp/python/3.6.8/python-3.6.8.exe

Try to run the installer from an elevated command prompt. If it fails
to run, check again for log files in your %TEMP% directory, which
typically expands to "C:\Users\\AppData\Local\Temp".

If the installer is still not running -- not even enough to create a
single log file -- then apparently something is configured incorrectly
or missing on your computer that's causing it to fail hard. I'd have
to run it under a debugger to find the cause.

Anyway, if you're stuck with ancient 3.4, you can at least install
"pywin32-221.win32-py3.4.exe" from the old SourceForge repo:

https://sourceforge.net/projects/pywin32/files/pywin32/Build%20221
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2019-07-06 Thread jfong
eryk sun於 2019年7月7日星期日 UTC+8下午12時00分47秒寫道:
> On 7/6/19, jf...@ms4.hinet.net  wrote:
> >
> > In TEMP, there is only one file "chrome_installer.log" dated at the time of
> > doing the upgrade (strange?, why chrome?). No errors in it.
> 
> So the installer doesn't even execute. Do you maybe have an
> anti-malware program that's blocking its execution?  Definitely try
> the 3.6.8 installer. I didn't pay attention to the fact that you were
> trying to install a very outdated version of 3.6. There may have been
> bugs in the installer that were fixed. Always use the most recent
> version possible.

I turn off the anti-virus and tried v3.6.8, get the same result. Usually the 
anti-virus program will warn me if something was blocked.

--Jach
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2019-07-06 Thread eryk sun
On 7/6/19, jf...@ms4.hinet.net  wrote:
>
> In TEMP, there is only one file "chrome_installer.log" dated at the time of
> doing the upgrade (strange?, why chrome?). No errors in it.

So the installer doesn't even execute. Do you maybe have an
anti-malware program that's blocking its execution?  Definitely try
the 3.6.8 installer. I didn't pay attention to the fact that you were
trying to install a very outdated version of 3.6. There may have been
bugs in the installer that were fixed. Always use the most recent
version possible.
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2019-07-06 Thread jfong
eryk sun於 2019年7月7日星期日 UTC+8上午10時13分34秒寫道:
> On 7/6/19, jf...@ms4.hinet.net  wrote:
> >
> > According to the info you give, I have done the following steps:
> > 1. Upgrade to SP2 first.
> > 2. Install the CRT update.
> > But the result is still the same, nothing happens after double click the
> > file python-3.6.1.exe.
> 
> Did you reboot after installing the updates? Afterward, did you
> confirm in the system properties that you're running SP2? Did you
> check that "%SystemRoot%\System32\ucrtbase.dll" exists, plus a bunch
> of "api-ms-win-crt-*.dll" DLLs in the same directory?
> 
> > I deeply appreciate your help. It looks like that Vista has to live with
> > Python 3.4 for its rest of life:-)
> 
> That is not true in general for Vista. It's particular to your
> computer. Check the installer logs in your %TEMP% directory for
> errors, which will typically be an HRESULT error code that starts with
> 0x8, such as 0x80070002.
> 
> Try downloading and installing the 64-bit version:
> 
> https://www.python.org/ftp/python/3.6.8/python-3.6.8-amd64.exe

Yes, it's SP2 showing up in Start->Computer->Properities window. Also in 
System32 directory, there is ucrtbase.dll and a bunch of api-ms-win-crt-*.dll 
too.

In TEMP, there is only one file "chrome_installer.log" dated at the time of 
doing the upgrade (strange?, why chrome?). No errors in it.

I can't. My Vista is 32bit. Anyway I will give v3.6.8 a try later.

--Jach
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2019-07-06 Thread eryk sun
On 7/6/19, jf...@ms4.hinet.net  wrote:
>
> According to the info you give, I have done the following steps:
> 1. Upgrade to SP2 first.
> 2. Install the CRT update.
> But the result is still the same, nothing happens after double click the
> file python-3.6.1.exe.

Did you reboot after installing the updates? Afterward, did you
confirm in the system properties that you're running SP2? Did you
check that "%SystemRoot%\System32\ucrtbase.dll" exists, plus a bunch
of "api-ms-win-crt-*.dll" DLLs in the same directory?

> I deeply appreciate your help. It looks like that Vista has to live with
> Python 3.4 for its rest of life:-)

That is not true in general for Vista. It's particular to your
computer. Check the installer logs in your %TEMP% directory for
errors, which will typically be an HRESULT error code that starts with
0x8, such as 0x80070002.

Try downloading and installing the 64-bit version:

https://www.python.org/ftp/python/3.6.8/python-3.6.8-amd64.exe
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2019-07-06 Thread jfong
eryk sun於 2019年7月6日星期六 UTC+8下午6時26分42秒寫道:
> On 7/6/19, jf...@ms4.hinet.net  wrote:
> > eryk sun於 2019年7月6日星期六 UTC+8下午2時13分23秒寫道:
> >
> >> Major versions of Python support Windows versions that have extended
> >> support from Microsoft at the time of the first release. For Vista,
> >> extended support ended on 2017-04-11. Python 3.6 was released on
> >> 2016-12-23, so it supports Vista. Python 3.7, on the other hand, does
> >> not because it was released on 2018-06-27.
> >
> > I tried the python-3.6.1.exe, downloaded from www.python.org. Its
> > release date is March 21, 2017. But it doesn't run, Vista has no response at
> > all.
> 
> Starting with version 3.5, Python requires the Universal C Runtime,
> which is an OS component that was introduced in Windows 10 and
> backported to previous versions, including Windows Vista (service pack
> 2). Python's installer should attempt to install the CRT update, but
> from what I've seen this isn't reliable.
> 
> Ideally, it shouldn't be necessary to manually install the CRT update
> since Windows Update includes it. Enable optional updates, and keep
> your system updated. That said, if you can't or won't use Windows
> Update, then you can download and install standalone updates.
> 
> CRT Update
> https://support.microsoft.com/en-us/help/3118401
> 
> The above requires Vista service pack 2 (SP2). The system properties
> dialog should say whether SP1 or SP2 is installed. Your system should
> be running SP2 if Windows Update is enabled. If you're not even
> running SP1, you'll have to install SP1 and then SP2. The system
> properties dialog will tell you whether you're running 32-bit or
> 64-bit Windows.
> 
> x86 32-bit SP1
> https://www.microsoft.com/en-us/download/details.aspx?id=30
> x64 64-bit SP2
> https://www.microsoft.com/en-us/download/details.aspx?id=21299
> 
> x86 32-bit SP2
> https://www.microsoft.com/en-us/download/details.aspx?id=16468
> x64 64-bit SP2
> https://www.microsoft.com/en-us/download/details.aspx?id=17669

According to the info you give, I have done the following steps:
1. Upgrade to SP2 first.
2. Install the CRT update.
But the result is still the same, nothing happens after double click the file 
python-3.6.1.exe.

I deeply appreciate your help. It looks like that Vista has to live with Python 
3.4 for its rest of life:-)

--Jach
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2019-07-06 Thread jfong
Michael Torrie於 2019年7月6日星期六 UTC+8下午12時02分02秒寫道:
> On 07/05/2019 09:03 PM, jf...@ms4.hinet.net wrote:
> > From Vista to Win10? That's a three generation gap! Buy a new PC might 
> > be a better solution:-)
> 
> Maybe.  Windows 10 would probably run okay on that machine. It might be
> 10 years old, but if it's 64-bit, Win 10 should run on it.
> 
> You could also buy a hard drive and download the ISO from Microsoft and
> give it a try.  If it works you can buy the license for it (sigh).
> 
> Of course there are also other good alternatives too.

Thank you for your suggestion. This PC was purchased in year 2006 from Dell. 
The CPU is AMD Athlon 64 X2 4000+. I doubt Win10 will support such an old 
CPU:-) and the chipset driver might be a big problem too.

--Jach
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2019-07-06 Thread eryk sun
On 7/6/19, jf...@ms4.hinet.net  wrote:
> eryk sun於 2019年7月6日星期六 UTC+8下午2時13分23秒寫道:
>
>> Major versions of Python support Windows versions that have extended
>> support from Microsoft at the time of the first release. For Vista,
>> extended support ended on 2017-04-11. Python 3.6 was released on
>> 2016-12-23, so it supports Vista. Python 3.7, on the other hand, does
>> not because it was released on 2018-06-27.
>
> I tried the python-3.6.1.exe, downloaded from www.python.org. Its
> release date is March 21, 2017. But it doesn't run, Vista has no response at
> all.

Starting with version 3.5, Python requires the Universal C Runtime,
which is an OS component that was introduced in Windows 10 and
backported to previous versions, including Windows Vista (service pack
2). Python's installer should attempt to install the CRT update, but
from what I've seen this isn't reliable.

Ideally, it shouldn't be necessary to manually install the CRT update
since Windows Update includes it. Enable optional updates, and keep
your system updated. That said, if you can't or won't use Windows
Update, then you can download and install standalone updates.

CRT Update
https://support.microsoft.com/en-us/help/3118401

The above requires Vista service pack 2 (SP2). The system properties
dialog should say whether SP1 or SP2 is installed. Your system should
be running SP2 if Windows Update is enabled. If you're not even
running SP1, you'll have to install SP1 and then SP2. The system
properties dialog will tell you whether you're running 32-bit or
64-bit Windows.

x86 32-bit SP1
https://www.microsoft.com/en-us/download/details.aspx?id=30
x64 64-bit SP2
https://www.microsoft.com/en-us/download/details.aspx?id=21299

x86 32-bit SP2
https://www.microsoft.com/en-us/download/details.aspx?id=16468
x64 64-bit SP2
https://www.microsoft.com/en-us/download/details.aspx?id=17669
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2019-07-06 Thread jfong
eryk sun於 2019年7月6日星期六 UTC+8下午2時13分23秒寫道:
> On 7/5/19, jf...@ms4.hinet.net  wrote:
> > Terry Reedy於 2019年7月5日星期五 UTC+8上午12時13分25秒寫道:
> >
> >> Upgrade to 3.7 or 3.8 to get hundreds of bug fixes, let alone new
> >> features.  Both subprocess and multiprocessing have gotten fixes.
> >
> > I can't because my OS is Vista and v3.4 is the last it can run:-( Also
> > the pywin32 can't be installed for it requires v3.5 and up.
> 
> Major versions of Python support Windows versions that have extended
> support from Microsoft at the time of the first release. For Vista,
> extended support ended on 2017-04-11. Python 3.6 was released on
> 2016-12-23, so it supports Vista. Python 3.7, on the other hand, does
> not because it was released on 2018-06-27.

I tried the python-3.6.1.exe, downloaded from www.python.org. Its release 
date is March 21, 2017. But it doesn't run, Vista has no response at all.

--Jach

> Windows 7 has extended support until 2020-01-14, so 3.8 supports it.
> However, system update KB2533623 is required for enhancements to the
> system loader that 3.8 depends on for loading extension modules and
> DLLs.
> 
> > I finally get a solution to switch between two notepads in Python. Here
> > is the codes for someone he may be interested.
> 
> If I have time I'll write a better version since the code you have is
> fragile. But I think you should take others' advice to use a
> cross-platform GUI automation library, so you won't be locked into a
> Windows-only solution.
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2019-07-05 Thread eryk sun
On 7/5/19, jf...@ms4.hinet.net  wrote:
> Terry Reedy於 2019年7月5日星期五 UTC+8上午12時13分25秒寫道:
>
>> Upgrade to 3.7 or 3.8 to get hundreds of bug fixes, let alone new
>> features.  Both subprocess and multiprocessing have gotten fixes.
>
> I can't because my OS is Vista and v3.4 is the last it can run:-( Also
> the pywin32 can't be installed for it requires v3.5 and up.

Major versions of Python support Windows versions that have extended
support from Microsoft at the time of the first release. For Vista,
extended support ended on 2017-04-11. Python 3.6 was released on
2016-12-23, so it supports Vista. Python 3.7, on the other hand, does
not because it was released on 2018-06-27.

Windows 7 has extended support until 2020-01-14, so 3.8 supports it.
However, system update KB2533623 is required for enhancements to the
system loader that 3.8 depends on for loading extension modules and
DLLs.

> I finally get a solution to switch between two notepads in Python. Here
> is the codes for someone he may be interested.

If I have time I'll write a better version since the code you have is
fragile. But I think you should take others' advice to use a
cross-platform GUI automation library, so you won't be locked into a
Windows-only solution.
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2019-07-05 Thread Chris Angelico
On Sat, Jul 6, 2019 at 2:03 PM Michael Torrie  wrote:
>
> On 07/05/2019 09:03 PM, jf...@ms4.hinet.net wrote:
> > From Vista to Win10? That's a three generation gap! Buy a new PC might 
> > be a better solution:-)
>
> Maybe.  Windows 10 would probably run okay on that machine. It might be
> 10 years old, but if it's 64-bit, Win 10 should run on it.
>
> You could also buy a hard drive and download the ISO from Microsoft and
> give it a try.  If it works you can buy the license for it (sigh).
>
> Of course there are also other good alternatives too.

When I said "upgrade to a better operating system", I wasn't being
specific. There are plenty of better OSes than Windows Vista; Win 10
is just one of them. Upgrading to the latest release of Debian
GNU/Linux would almost certainly solve your problem, as there is
plenty of support in any current Linux distro for managing other
programs. Of course, every decision has consequences, so it's up to
you to decide whether it's better to upgrade your existing hardware to
a newer Windows, switch to Linux, switch to BSD, buy new hardware, or
something else entirely.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2019-07-05 Thread Michael Torrie
On 07/05/2019 09:03 PM, jf...@ms4.hinet.net wrote:
> From Vista to Win10? That's a three generation gap! Buy a new PC might be 
> a better solution:-)

Maybe.  Windows 10 would probably run okay on that machine. It might be
10 years old, but if it's 64-bit, Win 10 should run on it.

You could also buy a hard drive and download the ISO from Microsoft and
give it a try.  If it works you can buy the license for it (sigh).

Of course there are also other good alternatives too.
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2019-07-05 Thread jfong
Chris Angelico於 2019年7月6日星期六 UTC+8上午10時48分10秒寫道:
> On Sat, Jul 6, 2019 at 12:31 PM  wrote:
> >
> > Terry Reedy於 2019年7月5日星期五 UTC+8上午12時13分25秒寫道:
> > > On 7/3/2019 7:57 PM, jf...@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.
> >
> > I can't because my OS is Vista and v3.4 is the last it can run:-( Also 
> > the pywin32 can't be installed for it requires v3.5 and up.
> >
> 
> So... upgrade to a better operating system?
> 
> ChrisA

From Vista to Win10? That's a three generation gap! Buy a new PC might be a 
better solution:-)

--Jach
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2019-07-05 Thread Chris Angelico
On Sat, Jul 6, 2019 at 12:31 PM  wrote:
>
> Terry Reedy於 2019年7月5日星期五 UTC+8上午12時13分25秒寫道:
> > On 7/3/2019 7:57 PM, jf...@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.
>
> I can't because my OS is Vista and v3.4 is the last it can run:-( Also 
> the pywin32 can't be installed for it requires v3.5 and up.
>

So... upgrade to a better operating system?

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2019-07-05 Thread jfong
Terry Reedy於 2019年7月5日星期五 UTC+8上午12時13分25秒寫道:
> On 7/3/2019 7:57 PM, jf...@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.

I can't because my OS is Vista and v3.4 is the last it can run:-( Also the 
pywin32 can't be installed for it requires v3.5 and up.

> 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.)

Can multiprocessing make debugging of eventloop app easier?

> If the subprocess runs a gui, the user should be able to switch focus by 
> clicking on a subprocess window.

I finally get a solution to switch between two notepads in Python. Here is 
the codes for someone he may be interested.
---
import subprocess, time, ctypes
user32 = ctypes.windll.user32

p0 = subprocess.Popen('notepad.exe')
time.sleep(1)
handle0 = user32.GetForegroundWindow()  # the handler of foreground window
thread0 = user32.GetWindowThreadProcessId(handle0, 0)  # get its thread id

p1 = subprocess.Popen('notepad.exe')
time.sleep(1)
handle1 = user32.GetForegroundWindow()
thread1 = user32.GetWindowThreadProcessId(handle1, 0)

for i in range(3):  # suppose the notepad1 is the foreground window
time.sleep(5)  # delay enough time for typing test
user32.AttachThreadInput(thread1, thread0, True)
user32.SetForegroundWindow(handle0)
time.sleep(5)
user32.AttachThreadInput(thread0, thread1, True)
user32.SetForegroundWindow(handle1)
print('end')

--Jach
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2019-07-04 Thread Terry Reedy

On 7/3/2019 7:57 PM, jf...@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

--
https://mail.python.org/mailman/listinfo/python-list


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

2019-07-03 Thread jfong
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  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 
> 
> 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/
> 
> -- 
>  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?
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2019-07-03 Thread Wildman via Python-list
On Thu, 04 Jul 2019 10:36:36 +1000, Cameron Simpson wrote:

> On 03Jul2019 16:57, Jach Fong  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 

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/

-- 
 GNU/Linux user #557453
The cow died so I don't need your bull!
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2019-07-03 Thread Chris Angelico
On Thu, Jul 4, 2019 at 11:31 AM  wrote:
>
> Chris Angelico於 2019年7月4日星期四 UTC+8上午8時37分13秒寫道:
> > On Thu, Jul 4, 2019 at 10:01 AM  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?
> > >
> >
> > The "communicate" method sends text to the standard input pipe. This
> > has nothing to do with the GUI, and most Windows GUI programs take no
> > notice of it. You'll need something GUI-aware for this.
> >
> > Is Notepad just an example, or are you actually trying to control MS 
> > Notepad?
> >
> > ChrisA
>
> Yes, the notepad is just an example. My real attempt is to operate the 
> external programs through Python. I know there are some "keyboard simulation" 
> packages in Pypi which may work on this situation. But I prefer not bother to 
> install them if Python's build-ins can do it.
>
> By the way, after Popen invokes an external program, is there a way of making 
> it on-foucs when there are multiple Popen instances?
>

Definitely look into GUI manipulation tools. What you're doing is
nothing to do with the subprocess module (at least, not with the way
most Windows apps are built).

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2019-07-03 Thread Aldwin Pollefeyt
This is same as   echo abcd | notepad.exein Command Prompt. You won't
see the abcd neither.

On Thu, Jul 4, 2019 at 8:41 AM Chris Angelico  wrote:

> On Thu, Jul 4, 2019 at 10:01 AM  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?
> >
>
> The "communicate" method sends text to the standard input pipe. This
> has nothing to do with the GUI, and most Windows GUI programs take no
> notice of it. You'll need something GUI-aware for this.
>
> Is Notepad just an example, or are you actually trying to control MS
> Notepad?
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2019-07-03 Thread jfong
Chris Angelico於 2019年7月4日星期四 UTC+8上午8時37分13秒寫道:
> On Thu, Jul 4, 2019 at 10:01 AM  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?
> >
> 
> The "communicate" method sends text to the standard input pipe. This
> has nothing to do with the GUI, and most Windows GUI programs take no
> notice of it. You'll need something GUI-aware for this.
> 
> Is Notepad just an example, or are you actually trying to control MS Notepad?
> 
> ChrisA

Yes, the notepad is just an example. My real attempt is to operate the external 
programs through Python. I know there are some "keyboard simulation" packages 
in Pypi which may work on this situation. But I prefer not bother to install 
them if Python's build-ins can do it.

By the way, after Popen invokes an external program, is there a way of making 
it on-foucs when there are multiple Popen instances?

--Jach
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2019-07-03 Thread Chris Angelico
On Thu, Jul 4, 2019 at 10:01 AM  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?
>

The "communicate" method sends text to the standard input pipe. This
has nothing to do with the GUI, and most Windows GUI programs take no
notice of it. You'll need something GUI-aware for this.

Is Notepad just an example, or are you actually trying to control MS Notepad?

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2019-07-03 Thread Cameron Simpson

On 03Jul2019 16:57, Jach Fong  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 
--
https://mail.python.org/mailman/listinfo/python-list


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

2019-07-03 Thread jfong
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
-- 
https://mail.python.org/mailman/listinfo/python-list