subprocess problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Do Re Mi chel La Si Do

    #1

    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



  • Uri Nix

    #2
    Re: subprocess problem

    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:[color=blue]
    > 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[/color]

    Comment

    • Do Re Mi chel La Si Do

      #3
      Re: subprocess problem

      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



      Comment

      Working...