• Post Reply Bookmark Topic Watch Topic
  • New Topic

runtime exec call with options that contain whitespace  RSS feed

 
Allen Smith
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lots of similar topics out there but none exactly the same as this one.

I need to call a program from my java application. This external program needs certain options...such as:

jpegtran -rotate 90 myimage.jpg

The problem is with the -rotate option...the whitespace is used as the delimiter and thus causing the command to be invalid.

Here is my String array holding the pieces:



And the call to runtime exec:



Any suggestions on how to keep '-rotate 90' together as one token?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm, that's kinda odd that what works if you type it on the command line won't work in the string. But try more quotes:

change "-rotate 90" to "\"-rotate 90\""
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
AFAIK > redirection will not work.

Google for 'javaworld pitfalls Runtime.exec' - there is a long explanation of all pitfalls.
 
Allen Smith
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
running on a unix system (HP-UX 10.20) so the redirection is not a problem...I have read the pitfalls but I was wondering if someone had found a way around the 'whitespace being used as the delimiter' portion of the design.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!