Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Peter Otten <__peter__@web.de> Newsgroups: comp.lang.python Subject: Re: Request More Help With XBM Image Date: Tue, 01 Mar 2016 19:26:55 +0100 Organization: None Lines: 72 Message-ID: References: <8rKdnb6SKYLRIEnLnZ2dnUU7-f3NnZ2d@giganews.com> <34GdnUOxhd5vS0jLnZ2dnUU7-Y3OydjZ@giganews.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Trace: news.uni-berlin.de hCrXxXb3PypNBlCtHcb7lgMJs76kn7b0x+p4hxTsAEZw== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'executable': 0.07; 'filename': 0.07; '__init__': 0.09; 'callback': 0.09; 'command.': 0.09; 'errread,': 0.09; 'expected.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'way:': 0.09; 'subject:Help': 0.10; 'python': 0.10; 'exception': 0.13; 'question.': 0.13; 'argument': 0.15; '2016': 0.16; 'err': 0.16; 'errwrite)': 0.16; 'oserror:': 0.16; 'presume': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'subject:More': 0.16; 'subprocess': 0.16; 'wrote:': 0.16; "shouldn't": 0.18; 'shell': 0.18; 'runs': 0.18; '>>>': 0.20; 'skip:" 30': 0.20; '(the': 0.22; '"",': 0.22; 'tkinter': 0.22; 'pass': 0.22; 'split': 0.23; '(most': 0.24; 'header:User-Agent:1': 0.26; 'example': 0.26; 'command': 0.26; 'header:X-Complaints-To:1': 0.26; 'linux': 0.26; 'skip:" 20': 0.26; 'error': 0.27; 'executing': 0.27; 'looks': 0.29; 'convert': 0.29; 'raise': 0.29; 'window': 0.30; 'error.': 0.31; 'guess': 0.31; 'post': 0.31; 'skip:_ 10': 0.32; 'run': 0.33; 'raised': 0.33; 'skip:/ 20': 0.33; 'traceback': 0.33; 'tue,': 0.34; 'file': 0.34; 'previous': 0.34; 'skip:c 30': 0.35; 'to:addr :python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'why': 0.39; 'does': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'received:de': 0.40; 'called': 0.40; 'mar': 0.65; 'python- list': 0.66; '3.4': 0.84; '__call__': 0.84; 'directory:': 0.84; 'otten': 0.84; 'subject:With': 0.93 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: p57bd89c3.dip0.t-ipconnect.de User-Agent: KNode/4.13.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:103812 Wildman via Python-list wrote: > On Tue, 01 Mar 2016 09:56:56 +0100, Peter Otten wrote: >> Wildman via Python-list wrote: >>> convert = "convert " + fileName + " -resize 48x48! -threshold 55% xbm:-" >>> p = subprocess.Popen([convert], stdout=subprocess.PIPE, shell=True) >>> xbmFile, err = p.communicate() >> Why would you need a shell? Just in case the example in my previous post has not made it clear: that was a rhetorical question. You do not need the shell, and in fact shouldn't use it. > I guess it is a Linux thing. If I don't use it, I get > the below error. A shell window does not actually open. > I presume it runs in the background while executing the > subprocess command. > Exception in Tkinter callback > Traceback (most recent call last): > File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1535, in __call__ > return self.func(*args) > File "./test.py", line 59, in open_image > p = subprocess.Popen(command, stdout=subprocess.PIPE) > File "/usr/lib/python2.7/subprocess.py", line 710, in __init__ > errread, errwrite) > File "/usr/lib/python2.7/subprocess.py", line 1335, in _execute_child > raise child_exception > OSError: [Errno 2] No such file or directory An exception is raised because you pass the command as a single argument like in [Python 2.7] >>> subprocess.Popen("ls /usr/share/dict/words") Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.7/subprocess.py", line 710, in __init__ errread, errwrite) File "/usr/lib/python2.7/subprocess.py", line 1327, in _execute_child raise child_exception OSError: [Errno 2] No such file or directory This looks for an executable called "ls /usr/share/dict/words" (the whole shebang!) where you actually want to run "ls" with the argument "/usr/share/dict/words". Once you split the parts >>> subprocess.Popen(["ls", "/usr/share/dict/words"]) >>> /usr/share/dict/words everything works as expected. The error message in Python 3.4 would have given you a clue, by the way: [Python 3.4] >>> subprocess.Popen("ls /usr/share/dict/words") Traceback (most recent call last): File "", line 1, in File "/usr/lib/python3.4/subprocess.py", line 859, in __init__ restore_signals, start_new_session) File "/usr/lib/python3.4/subprocess.py", line 1457, in _execute_child raise child_exception_type(errno_num, err_msg) FileNotFoundError: [Errno 2] No such file or directory: 'ls /usr/share/dict/words'