You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Natalia Bello <NB...@isabel.be> on 2002/03/05 15:55:52 UTC

Own task. Commandline

Hello! 
I am trying to develop my own task; in this task I need to execute a command
line like this:
cmdclient -user "integrator" -pass "password" ..
that is, i need to set the arguments between double quotes!! 
I have tried some posibilites, but i havent success!
If i try for example
        Commandline commandLine = new Commandline();
        commandLine.setExecutable("cmdclient");
        commandLine.createArgument().setValue("-user \"integrator\"");
        log("Executing " + commandLine.toString());

I get:
   [CBL] Executing cmdclient '-user "integrator"'

or this other
   	Commandline commandLine = new Commandline();
	commandLine.setExecutable("cmdclient");
        	commandLine.createArgument().setLine("-user
\"integrator\"");
            log("Executing " + commandLine.toString()); 
I get:
	 [CBL] Executing cmdclient -user integrator

or:
              Commandline commandLine = new Commandline();
	  commandLine.setExecutable("cmdclient");
	  commandLine.createArgument().setValue("-user");
	  commandLine.createArgument().setValue("\"integrator\"");
              log("Executing " + commandLine.toString()); 

I get again: 
	 [CBL] Executing cmdclient -user integrator

Does anyone now how i can do this?
Thanks in advanced,
Natalia

RE: Own task. Commandline

Posted by Adam Murdoch <ad...@yahoo.com>.
Hi,

The Sun JVM does a really poor job of dealing with quotes in arguments.  One
way you can get around this is to wrap your double-quoted arg in
single-quotes.

For example, in the following:

>               Commandline commandLine = new Commandline();
> 	  commandLine.setExecutable("cmdclient");
> 	  commandLine.createArgument().setValue("-user");
> 	  commandLine.createArgument().setValue("\"integrator\"");

replace the last line with

commandLine.createArgument().setValue("\'\"integrator\"\'");

This works for Sun JVMs on Windows.  Don't know about other platforms or
JVMs.

Perhaps a better option is to fix the executable to behave a little better
as a command-line tool.  Or write a wrapper script.


Adam

> -----Original Message-----
> From: Natalia Bello [mailto:NBELLO@isabel.be]
> Sent: Wednesday, 6 March 2002 12:56 AM
> To: 'Ant Users List'
> Subject: Own task. Commandline
>
>
> Hello!
> I am trying to develop my own task; in this task I need to
> execute a command
> line like this:
> cmdclient -user "integrator" -pass "password" ..
> that is, i need to set the arguments between double quotes!!
> I have tried some posibilites, but i havent success!
> If i try for example
>         Commandline commandLine = new Commandline();
>         commandLine.setExecutable("cmdclient");
>         commandLine.createArgument().setValue("-user \"integrator\"");
>         log("Executing " + commandLine.toString());
>
> I get:
>    [CBL] Executing cmdclient '-user "integrator"'
>
> or this other
>    	Commandline commandLine = new Commandline();
> 	commandLine.setExecutable("cmdclient");
>         	commandLine.createArgument().setLine("-user
> \"integrator\"");
>             log("Executing " + commandLine.toString());
> I get:
> 	 [CBL] Executing cmdclient -user integrator
>
> or:
>               Commandline commandLine = new Commandline();
> 	  commandLine.setExecutable("cmdclient");
> 	  commandLine.createArgument().setValue("-user");
> 	  commandLine.createArgument().setValue("\"integrator\"");
>               log("Executing " + commandLine.toString());
>
> I get again:
> 	 [CBL] Executing cmdclient -user integrator
>
> Does anyone now how i can do this?
> Thanks in advanced,
> Natalia
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>