Hi all,
I've been trying to use (Python 2.4 on WinXP) the subprocess module to
execute a shell command (nmake in this case), and pass its output to a
higher level.
Using the following snippet:
p =
subprocess.Popen(nmake,stderr=subprocess.PIPE,stdo ut=subprocess.PIPE, \
universal_newlines=True, bufsize=1)
os.sys.stdout.writelines(p.stdout)
os.sys.stdout.writelines(p.stderr)
Works fine on the command line, but fails when called from within
Visual Studio, with the following error:
File "C:\Python24\lib\subprocess.py", line 549, in __init__
(p2cread, p2cwrite,
File "C:\Python24\lib\subprocess.py", line 609, in _get_handles
p2cread = self._make_inheritable(p2cread)
File "C:\Python24\lib\subprocess.py", line 650, in _make_inheritable
DUPLICATE_SAME_ACCESS)
TypeError: an integer is required
If I replace the functionality with:
p = os.popen4(nmake)
# p[1] = stdout_and_stderr result pipe
p[1].flush()
os.sys.stdout.writelines(p[1].readlines())
All is well.
I have a feeling this has been encountered before (by googling here),
but didn't see any concise answer as to subprocess' robustness.
So what is the matter here? And should I consider the subprocess
module still unstable?
Cheers,
Uri 6 1716
Hi also !
In other fields, I also found uses which did not function with subprocess,
but OK with popen2/4
@-salutations
Michel Claveau
Uri Nix wrote: Using the following snippet: p = subprocess.Popen(nmake,stderr=subprocess.PIPE,stdo ut=subprocess.PIPE, \ universal_newlines=True, bufsize=1) os.sys.stdout.writelines(p.stdout) os.sys.stdout.writelines(p.stderr) Works fine on the command line, but fails when called from within Visual Studio, with the following error: File "C:\Python24\lib\subprocess.py", line 549, in __init__ (p2cread, p2cwrite, File "C:\Python24\lib\subprocess.py", line 609, in _get_handles p2cread = self._make_inheritable(p2cread) File "C:\Python24\lib\subprocess.py", line 650, in _make_inheritable DUPLICATE_SAME_ACCESS) TypeError: an integer is required
This looks like these known bugs: http://python.org/sf/1124861 http://python.org/sf/1126208
Try setting stderr to subprocess.PIPE. I think that was what worked for
me. (You might also try setting shell=True. That's what I currently
have in my code that didn't work before.)
STeVe
Steven Bethard wrote: Using the following snippet: p = subprocess.Popen(nmake,stderr=subprocess.PIPE,stdo ut=subprocess.PIPE, \ universal_newlines=True, bufsize=1) os.sys.stdout.writelines(p.stdout) os.sys.stdout.writelines(p.stderr) Works fine on the command line, but fails when called from within Visual Studio, with the following error: File "C:\Python24\lib\subprocess.py", line 549, in __init__ (p2cread, p2cwrite, File "C:\Python24\lib\subprocess.py", line 609, in _get_handles p2cread = self._make_inheritable(p2cread) File "C:\Python24\lib\subprocess.py", line 650, in _make_inheritable DUPLICATE_SAME_ACCESS) TypeError: an integer is required
This looks like these known bugs: http://python.org/sf/1124861 http://python.org/sf/1126208
Try setting stderr to subprocess.PIPE. I think that was what worked for me. (You might also try setting shell=True. That's what I currently have in my code that didn't work before.)
if someone wants to investigate, is seeing this problem, and have the win32
extensions on their machine, try changing this line in subprocess.py:
if 0: # <-- change this to use pywin32 instead of the _subprocess driver
to:
if 1: # <-- change this to use _subprocess instead of the pywin32 driver
and see if it either fixes the problem (not very likely) or gives you a better
error message (very likely).
</F>
"Fredrik Lundh" <fr*****@pythonware.com> wrote in message news:ma************************************@python .org... Steven Bethard wrote:
> Using the following snippet: > p = > subprocess.Popen(nmake,stderr=subprocess.PIPE,stdo ut=subprocess.PIPE, \ > universal_newlines=True, bufsize=1) > os.sys.stdout.writelines(p.stdout) > os.sys.stdout.writelines(p.stderr) > Works fine on the command line, but fails when called from within > Visual Studio, with the following error: > File "C:\Python24\lib\subprocess.py", line 549, in __init__ > (p2cread, p2cwrite, > File "C:\Python24\lib\subprocess.py", line 609, in _get_handles > p2cread = self._make_inheritable(p2cread) > File "C:\Python24\lib\subprocess.py", line 650, in _make_inheritable > DUPLICATE_SAME_ACCESS) > TypeError: an integer is required
This looks like these known bugs: http://python.org/sf/1124861 http://python.org/sf/1126208
Try setting stderr to subprocess.PIPE. I think that was what worked for me. (You might also try setting shell=True. That's what I currently have in my code that didn't work before.)
if someone wants to investigate, is seeing this problem, and have the win32 extensions on their machine, try changing this line in subprocess.py:
if 0: # <-- change this to use pywin32 instead of the _subprocess driver
to:
if 1: # <-- change this to use _subprocess instead of the pywin32 driver
and see if it either fixes the problem (not very likely) or gives you a better error message (very likely).
</F>
The error msg is only slightly better:
error: (6, 'DuplicateHandle', 'The handle is invalid.')
Basically, gui apps like VS don't have a console, so
GetStdHandle returns 0. _subprocess.GetStdHandle
returns None if the handle is 0, which gives the original
error. Pywin32 just returns the 0, so the process gets
one step further but still hits the above error.
Subprocess.py should probably check the
result of GetStdHandle for None (or 0)
and throw a readable error that says something like
"No standard handle available, you must specify one"
Roger
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Roger Upole wrote: "Fredrik Lundh" <fr*****@pythonware.com> wrote in message news:ma************************************@python .org... Steven Bethard wrote:
> Using the following snippet: > p = > subprocess.Popen(nmake,stderr=subprocess.PIPE,stdo ut=subprocess.PIPE, \ > universal_newlines=True, bufsize=1) > os.sys.stdout.writelines(p.stdout) > os.sys.stdout.writelines(p.stderr) > Works fine on the command line, but fails when called from within > Visual Studio, with the following error: > File "C:\Python24\lib\subprocess.py", line 549, in __init__ > (p2cread, p2cwrite, > File "C:\Python24\lib\subprocess.py", line 609, in _get_handles > p2cread = self._make_inheritable(p2cread) > File "C:\Python24\lib\subprocess.py", line 650, in _make_inheritable > DUPLICATE_SAME_ACCESS) > TypeError: an integer is required
This looks like these known bugs: http://python.org/sf/1124861 http://python.org/sf/1126208
Try setting stderr to subprocess.PIPE. I think that was what worked for me. (You might also try setting shell=True. That's what I currently have in my code that didn't work before.)
if someone wants to investigate, is seeing this problem, and have the win32 extensions on their machine, try changing this line in subprocess.py:
if 0: # <-- change this to use pywin32 instead of the _subprocess driver
to:
if 1: # <-- change this to use _subprocess instead of the pywin32 driver
and see if it either fixes the problem (not very likely) or gives you a better error message (very likely).
</F>
The error msg is only slightly better:
error: (6, 'DuplicateHandle', 'The handle is invalid.')
Basically, gui apps like VS don't have a console, so GetStdHandle returns 0. _subprocess.GetStdHandle returns None if the handle is 0, which gives the original error. Pywin32 just returns the 0, so the process gets one step further but still hits the above error.
Subprocess.py should probably check the result of GetStdHandle for None (or 0) and throw a readable error that says something like "No standard handle available, you must specify one"
Roger
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
I gathered as much about why this happens in VS. A further question is
why does n't os.popen fall in the same trap?
Cheers,
Uri
"Uri Nix" <Ur*****@gmail.com> wrote in message news:11*********************@g49g2000cwa.googlegro ups.com... Roger Upole wrote: "Fredrik Lundh" <fr*****@pythonware.com> wrote in message news:ma************************************@python .org... > Steven Bethard wrote: > >> > Using the following snippet: >> > p = >> > subprocess.Popen(nmake,stderr=subprocess.PIPE,stdo ut=subprocess.PIPE, \ >> > universal_newlines=True, bufsize=1) >> > os.sys.stdout.writelines(p.stdout) >> > os.sys.stdout.writelines(p.stderr) >> > Works fine on the command line, but fails when called from within >> > Visual Studio, with the following error: >> > File "C:\Python24\lib\subprocess.py", line 549, in __init__ >> > (p2cread, p2cwrite, >> > File "C:\Python24\lib\subprocess.py", line 609, in _get_handles >> > p2cread = self._make_inheritable(p2cread) >> > File "C:\Python24\lib\subprocess.py", line 650, in _make_inheritable >> > DUPLICATE_SAME_ACCESS) >> > TypeError: an integer is required >> >> This looks like these known bugs: >> http://python.org/sf/1124861 >> http://python.org/sf/1126208 >> >> Try setting stderr to subprocess.PIPE. I think that was what worked for >> me. (You might also try setting shell=True. That's what I currently >> have in my code that didn't work before.) > > if someone wants to investigate, is seeing this problem, and have the win32 > extensions on their machine, try changing this line in subprocess.py: > > if 0: # <-- change this to use pywin32 instead of the _subprocess driver > > to: > > if 1: # <-- change this to use _subprocess instead of the pywin32 driver > > and see if it either fixes the problem (not very likely) or gives you a better > error message (very likely). > > </F> >
The error msg is only slightly better:
error: (6, 'DuplicateHandle', 'The handle is invalid.')
Basically, gui apps like VS don't have a console, so GetStdHandle returns 0. _subprocess.GetStdHandle returns None if the handle is 0, which gives the original error. Pywin32 just returns the 0, so the process gets one step further but still hits the above error.
Subprocess.py should probably check the result of GetStdHandle for None (or 0) and throw a readable error that says something like "No standard handle available, you must specify one"
Roger
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
I gathered as much about why this happens in VS. A further question is why does n't os.popen fall in the same trap?
Cheers, Uri
From a quick glance at the source, it looks like it always
creates new pipes.
Roger
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =---- This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Stewart Midwinter |
last post by:
this has me puzzled; I've created a small test app to show the problem
I'm having.
I want to use subprocess to execute system commands from inside a
Tkinter app running under Cygwin.
When I...
|
by: Darren Dale |
last post by:
I'm a developer on the matplotlib project, and I am having trouble with the
subprocess module on windows (Python 2.4.2 on winXP). No trouble to report
with linux. I need to use _subprocess instead...
|
by: bayer.justin |
last post by:
Hi,
I am trying to communicate with a subprocess via the subprocess
module. Consider the following example:
<subprocess.Popen object at 0x729f0>
Here hey is immediately print to stdout of...
|
by: Grant Edwards |
last post by:
I'm trying to use the py-gnuplot module on windows, and have
been unable to get it to work reliably under Win2K and WinXP.
By default, it uses popen(gnuplotcmd,'w'), but in some
situations that...
|
by: Phoe6 |
last post by:
Hi all,
Consider this scenario, where in I need to use subprocess to execute a
command like 'ping 127.0.0.1' which will have a continuous non-
terminating output in Linux.
# code
# This...
|
by: JD |
last post by:
Hi,
I want send my jobs over a whole bunch of machines (using ssh). The
jobs will need to be run in the following pattern:
(Machine A) (Machine B) (Machine C)
Job A1 Job B1 ...
|
by: bhunter |
last post by:
Hi,
I've used subprocess with 2.4 several times to execute a process, wait
for it to finish, and then look at its output. Now I want to spawn
the process separately, later check to see if it's...
|
by: skunkwerk |
last post by:
Hi,
i'm trying to call subprocess.popen on the 'rename' function in
linux. When I run the command from the shell, like so:
rename -vn 's/\.htm$/\.html/' *.htm
it works fine... however when I...
|
by: Jeremy Banks |
last post by:
Hi. I wondered if anyone knew the rationale behind the naming of the
Popen class in the subprocess module. Popen sounds like the a suitable
name for a function that created a subprocess, but the...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |