home | list info | list archive | date index | thread index

Re: [OCLUG-Tech] Re: ps2pdf and xargs

On Tue, Sep 20, 2005 at 08:56:00AM -0800, J C Nash wrote:
> I wanted to convert all the ps files in a directory, so
> tried
> ls *.ps | xargs ps2pdf
> but got the "usage" msg from ps2pdf. Tried a few alternative
> with no joy and finally wrote a perl script that does a nice
> job (available on request). However, I'd like to know why
> xargs doesn't work here.

As you can see from its usage message, ps2pdf expects at most two non-option arguments: the input file and the output file.  For example:

ps2pdf a.ps b.ps c.ps

is invalid and

ps2pdf a.ps b.ps

is valid but probably won't do what you want.

If you want to use xargs, you can instruct it to pass at most one
argument to ps2pdf per invocation:

ls *.ps | xargs -n 1 ps2pdf

To test xargs out, I suggest you try both your command and my suggestion
with 'echo' in front of 'ps2pdf'.  That way you'll be able to see
exactly how xargs is invoking ps2pdf.

Also, this is unrelated to your question, but unless you're sure
filenames will not contain whitespace, commands like what you're doing
should be avoided.  Instead, you can do:

find . -maxdepth 1 -name '*.ps' -print0 | xargs -0 -n 1 ps2pdf

or similar.  If you're sure there aren't any spaces, don't worry about
it :)


> J C Nash
> ----------------------------------------
> Upgrade your account today for increased storage; mail
> forwarding or POP enabled e-mail with automatic virus
> scanning. Visit
> http://www.canada.com/email/premiumservices.html for more
> information.
> _______________________________________________
> Linux mailing list
> Linux [ at ] lists [ dot ] oclug [ dot ] on [ dot ] ca
> http://www.oclug.on.ca/mailman/listinfo/linux