Request More Help With XBM Image
Peter Otten
__peter__ at web.de
Tue Mar 1 13:26:55 EST 2016
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 "<stdin>", line 1, in <module>
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"])
<subprocess.Popen object at 0x7fa6286d6250>
>>> /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 "<stdin>", line 1, in <module>
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'
More information about the Python-list
mailing list