Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pbs.convert raise an error #59

Closed
ifduyue opened this issue Mar 26, 2012 · 4 comments
Closed

pbs.convert raise an error #59

ifduyue opened this issue Mar 26, 2012 · 4 comments

Comments

@ifduyue
Copy link

ifduyue commented Mar 26, 2012

here is the command:

import pbs
pbs.convert("-crop +0+67", "some.jpg", "crop.jpg")

raises an error:

Traceback (most recent call last):
  File "test.py", line 5, in <module>
    pbs.convert("-crop +0+67", "some.jpg", "crop.jpg")
  File "/usr/lib/python2.7/site-packages/pbs.py", line 436, in __call__
    return RunningCommand(command_ran, process, call_args, actual_stdin)
  File "/usr/lib/python2.7/site-packages/pbs.py", line 142, in __init__
    self._handle_exit_code(self.process.wait())
  File "/usr/lib/python2.7/site-packages/pbs.py", line 207, in _handle_exit_code
    raise get_rc_exc(rc)(self.command_ran, self._stdout, self._stderr)
pbs.ErrorReturnCode_1: 

Ran: '/usr/bin/convert -crop +0+67 some.jpg crop.jpg'

STDOUT:



STDERR:

  convert: unrecognized option `-crop +0+67' @ error/convert.c/ConvertImageCommand/10

I found that subprocess.Popen(["/usr/bin/convert", "-crop", "+0+67", "some.jpg", "crop.jpg"]) is OK,
but subprocess.Popen(["/usr/bin/convert", "-crop +0+67", "some.jpg", "crop.jpg"]) is NOT.

Maybe this is not a bug, maybe it's subprocess's bug.
However, can psb take this situation into account and work around?

Thanks.

Best regards,
Du Yue

@ifduyue
Copy link
Author

ifduyue commented Mar 26, 2012

convert is a command tool ImageMagick provides

@amoffat
Copy link
Owner

amoffat commented Mar 26, 2012

Hi Du, unfortunately this is a problem with how pbs and shlex split up arguments. There will be a workaround in v1.0 if I can find it, but in the meantime, you can do this:

pbs.convert("-crop", "+0+67", "some.jpg", "crop.jpg")

@amoffat
Copy link
Owner

amoffat commented Apr 4, 2012

Just an update, there will be no workaround in v1.0. It seems that the best way to handle passing arguments to commands is to split them up with the understanding that 1 argument to the pbs command should correspond to 1 argument being passed to the subprocess. I've updated the readme to reflect this.

So in other words, this:

pbs.convert("-crop +0+67", "some.jpg", "crop.jpg")

should always be this:

pbs.convert("-crop", "+0+67", "some.jpg", "crop.jpg")

Because "-crop" and "+0+67" are separate arguments to the "convert" binary, and using shlex.split() to split up arguments automagically is broken and full of problems.

@amoffat amoffat closed this as completed Apr 4, 2012
@ifduyue
Copy link
Author

ifduyue commented Apr 5, 2012

pbs.convert("-crop", "+0+67", "some.jpg", "crop.jpg") works.

thanks, amoffat.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants