Once again ...
-------- Original Message --------
Subject: Re: [EXEC] Quoting of arguments
Date: Thu, 24 Apr 2008 14:11:07 +0200
From: Siegfried Goeschl <[EMAIL PROTECTED]>
Reply-To: [EMAIL PROTECTED]
To: Commons Users List <user@commons.apache.org>
References: <[EMAIL PROTECTED]>
Hi Tino,
it is recommended to build up the command line using individual
arguments where you can turn off quoting - see
http://commons.apache.org/sandbox/exec/apidocs/org/apache/commons/exec/CommandLine.html#addArgument(java.lang.String,%20boolean)
Having said that the CommandLine.parse() seems buggy
1) "cmd /C convert ${in} -resize \"\'500x>\'\" ${out}" ==> cmd /C
convert source.jpg -resize 500x> target.jpg
2) "cmd /C convert ${in} -resize \"\'500x> \'\" ${out}" ==> cmd /C
convert source.jpg -resize "500x> " target.jpg
So to make that work I need "'500x> '" - please note that extra space!!!
- if I leave out the extra space your extra quotes are dropped. I added
a test to pinpoint the problem
Cheers,
Siegfried Goeschl
public void _testParseComplexCommandLine1() throws Exception {
HashMap substitutionMap = new HashMap();
substitutionMap.put("in", "source.jpg");
substitutionMap.put("out", "target.jpg");
CommandLine cmdl = CommandLine.parse("cmd /C convert ${in} -resize
\"\'500x>\'\" ${out}", substitutionMap);
assertEquals("cmd /C convert source.jpg -resize \"500x>\"
target.jpg", cmdl.toString());
return;
}
Tino Schöllhorn wrote:
Hi,
I am trying to switch to commons-exec. Now I found the following
issue: We have small commandline-wrapper around "ImageMagick". So we
have a commandline which is something like:
cmd /C convert ${in} -resize "500x>" ${out}
When using that command with a "simple" Process without parsing etc
the command executes fine. But when using EXEC with CommandLine.parse
there is an error as EXEC is discarding the quotes (").
When I debug the corresponding CommandLine-Object I get the arguments
like that:
cmd
/c
convert
${in}
-resize
500x>
${out}
ImageMagick needs those quotes on our target platforms (Windows and
Linux). So is there a way to protect those quotes?
Cheers,
Tino
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]