473,698 Members | 2,480 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

subprocess problem

Hi!

This script (under Win-XP + P-2.4.1) :
import subprocess
p1=subprocess.P open(r'cmd /cdir *.* /S /W /B', stdout=subproce ss.PIPE)
chaineretour=p1 .stdout.read()

run OK if called from DOS-console. But, from another Python's script (by COM
+ exec) give me an error.

Here, the traceback :

Traceback (most recent call last):
File "D:\dev\Python\ ponx.py", line 4446, in PRun
exec(ccod,globa ls(),globals())
File "C:\Python24\li b\subprocess.py ", line 546, in __init__
(p2cread, p2cwrite,
File "C:\Python24\li b\subprocess.py ", line 606, in __get_handles__
p2cread = self._make_inhe ritable(p2cread )
File "C:\Python24\li b\subprocess.py ", line 647, in _make_inheritab le
DUPLICATE_SAME_ ACCESS)
error: (6, 'DuplicateHandl e','Descripteur non valide')
I know the bug-signaled : http://python.org/sf/1124861
But... a idea for a solution ?

Thanks, and sorry for my bad english.
Michel Claveau

Sep 28 '05 #1
2 1933
Hi,

I had a similar problem recently, and found that using pipes with
os.popen* helped in my case.
You can check the thread at:
http://mail.python.org/pipermail/pyt...er/300744.html.

Cheers,
Uri

Do Re Mi chel La Si Do wrote:
Hi!

This script (under Win-XP + P-2.4.1) :
import subprocess
p1=subprocess.P open(r'cmd /cdir *.* /S /W /B', stdout=subproce ss.PIPE)
chaineretour=p1 .stdout.read()

run OK if called from DOS-console. But, from another Python's script (by COM
+ exec) give me an error.

Here, the traceback :

Traceback (most recent call last):
File "D:\dev\Python\ ponx.py", line 4446, in PRun
exec(ccod,globa ls(),globals())
File "C:\Python24\li b\subprocess.py ", line 546, in __init__
(p2cread, p2cwrite,
File "C:\Python24\li b\subprocess.py ", line 606, in __get_handles__
p2cread = self._make_inhe ritable(p2cread )
File "C:\Python24\li b\subprocess.py ", line 647, in _make_inheritab le
DUPLICATE_SAME_ ACCESS)
error: (6, 'DuplicateHandl e','Descripteur non valide')
I know the bug-signaled : http://python.org/sf/1124861
But... a idea for a solution ?

Thanks, and sorry for my bad english.
Michel Claveau


Sep 28 '05 #2
Hi !

Thank you very much.

With your tip, this script :

import os
p = os.popen4(r'cmd /k')
p[0].write('dir *.bat /B\r\n')
p[0].flush()
p[0].write('dir *.cfg \r\n')
p[0].flush()
p[0].write('exit\r\ n')
p[0].flush()
print ''.join(p[1].readlines())

run perfectly

@-salutations

Michel Claveau

Sep 29 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2449
by: Roman Neuhauser | last post by:
Hello, I have a piece of code that gets run in a script that has its stdout closed: import sys sys.stdout = sys.stderr c = subprocess.Popen (..., stdin = subprocess.PIPE,
6
1732
by: Uri Nix | last post by:
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,stdout=subprocess.PIPE, \ universal_newlines=True, bufsize=1)
4
3396
by: Marc Carter | last post by:
I am trying to rewrite a PERL automation which started a "monitoring" application on many machines, via RSH, and then multiplexed their collective outputs to stdout. In production there are lots of these subprocesses but here is a simplified example what I have so far (python n00b alert!) - SNIP --------- import subprocess,select,sys speakers=
2
4081
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 open a python interpreter and run my subprocess command, all is well. But when I run the same command from inside a Tkinter app, I'm getting errors.
3
12747
by: madpython | last post by:
playing with subprocess.Popen on Windows I stumbled into the following problem: Python 2.4.3 (#69, Mar 29 2006, 17:35:34) IDLE 1.1.3 >>> import subprocess >>> p1=subprocess.Popen("c:\\asd.bat") #works OK >>> p2=subprocess.Popen("c:\\asd.bat",stdout=subprocess.PIPE)
12
10984
by: Eric_Dexter | last post by:
I am trying to modify a programming example and I am coming up with two problems... first is that I can't seem to pass along the arguments to the external command (I have been able to do that with the old module and cmd is the command I wish to try) all the output seems to be returned as one line (at least when I run the program in spe). import subprocess from os import system cmd = """gawk -f altertime.awk -v time_offset=4 -v
1
3984
by: Mrown | last post by:
Hi, I'm currently writing a python program that relies on a CLI program. What I'm currently doing is using subprocess.Popen on Python 2.5.1. Here's the line that I'm currently running: child = subprocess.Popen(, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) The problem is that although the above works, a CMD shell is spawned and becomes visible for each time I run the above. I thought that by
0
196
by: Michel Lespinasse | last post by:
On Thu, Aug 28, 2008 at 10:37:48AM +0100, Tim Golden wrote: The root cause is different (subprocess has separate implementations for windows and posix), but the issues are similar. In the posix case, I only observed the issue when you using subprocess.PIPE The attached patch against subprocess.py (as shipped on debian etch, based on python version 2.4.4) seems to work for me: --- /usr/lib/python2.4/subprocess.py 2008-04-16...
3
2135
by: topazcode | last post by:
I am using the subprocess module to run some shell commands on a Linux system: import subprocess output = subprocess.call('''ssh server1 "uptime"''', shell=True) The above assigns the output variable with a return code, i.e. 0 in this case. How can I actually capture the data returned from subprocess.call, rather than just the return code? I'd like to have the output variable contain the uptime string in this case. Any help
0
990
by: Amanda Jamin | last post by:
Subprocess issues with platform independence Postby ajamin on Wed Oct 08, 2008 10:46 am I am writing a python script that will act as a wrapper for another program. The python script will provide the inputs for this program and will verify that the output is correct. The application runs on multiple OS's including windows and *nix. This is the code:
0
8608
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9161
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9029
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8897
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8867
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2332
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2006
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.