subprocess problem in cygwin with Tkinter

Stewart Midwinter stewart.midwinter at gmail.com
Wed Jan 4 21:02:01 EST 2006


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.

I'm using this version of Cygwin:
$ uname -a
CYGWIN_NT-5.1 Mulata 1.5.18(0.132/4/2) 2005-07-02 20:30 i686 unknown unknown Cyg
win

When I run my command in a python shell, all is well:

smidwint at Mulata /cygdrive/c/programs/pipeworksb/lib/python/popt
$ python
Python 2.4.1 (#1, May 27 2005, 18:02:40)
[GCC 3.3.3 (cygwin special)] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> dirlist = subprocess.Popen('/usr/bin/ls', shell=True, bufsize=2048, stdout=
subprocess.PIPE).stdout
>>> dirlist
<open file '<fdopen>', mode 'rb' at 0x49d848>
>>> for dir in dirlist:
...     print dir
...
__init__.pyc
browser.bat
test_subprocess.py
test_subprocess.py.bak
>>>


When I run the same command in a Tkinter app, I get an exception:

smidwint at Mulata /cygdrive/c/programs/pipeworksb/lib/python/popt
$ python test_subprocess.py
d:\cygwin\bin\python2.4.exe (7752): *** unable to remap d:\cygwin\bin\tk84.dll t
o same address as parent(0x18C40000) != 0x18C50000
      9 [main] python 4696 fork_parent: child 7752 died waiting for dll loading
Traceback (most recent call last):
  File "test_subprocess.py", line 19, in ?
    l = Tkinter.Label(text=dir_list())
  File "test_subprocess.py", line 8, in dir_list
    dirlist = subprocess.Popen('/usr/bin/ls', shell=True, bufsize=2048, stdout=s
ubprocess.PIPE).stdout
  File "/usr/lib/python2.4/subprocess.py", line 558, in __init__
    errread, errwrite)
  File "/usr/lib/python2.4/subprocess.py", line 918, in _execute_child
    self.pid = os.fork()
OSError: [Errno 2] No such file or directory


Here's a sample Tkinter app that reproduces the problem:

#test_subprocess.py
import subprocess, os
import Tkinter

def dir_list():
    '''provide a listing of files in a directory'''
    #need to know which system to draw from
    curdir = os.getcwd()
    dirlist = subprocess.Popen('/usr/bin/ls', shell=True,
bufsize=2048, stdout=subprocess.PIPE).stdout
    #dirlist = subprocess.Popen(['ls',' -l'],
stdout=subprocess.PIPE).stdout.communicate()[0]
    print dirlist
    msgList = []
    for dir in dirlist:
        print dir
        msgList.append(dir)
    msg = '\n'.join(msgList)
    return msg

root = Tkinter.Tk()
l = Tkinter.Label(text=dir_list())
l.pack()
b = Tkinter.Button(text='ok',command=root.destroy)
b.pack()
root.mainloop()


BTW, the test_subprocess.py test script that ships with Cygwin python runs fine.

any ideas?
thanks,
--
Stewart Midwinter
stewart at midwinter.ca
stewart.midwinter at gmail.com
Skype, GoogleTalk, iChatAV, MSN, Yahoo: midtoad
AIM:midtoad1



More information about the Python-list mailing list