commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Siegfried Goeschl <sgoes...@gmx.at>
Subject Re: [EXEC] Quoting of arguments
Date Thu, 24 Apr 2008 12:11:07 GMT
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: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message