You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by David Parks <da...@yahoo.com> on 2011/06/28 05:34:32 UTC

Ant 1.8.3alpha: task fails to handle quotes within quotes command lines

I'm trying to run a command with both single and double quotes through <exec
...>. I am using last nights build of ant 1.8.3alpha (I should note the same
behavior on 1.8.2). But the arguments appear to be incorrectly passed to the
command line, as per the following demonstration.

This command runs from a DOS command line perfectly:

c:\cygwin\bin\bash.exe -c 'read var;expect -d -c "spawn rsync -aOvz
--chmod=Du=rwx,Dg=rx,Do=rx,Fu=rw,Fg=r,Fo=r -e ssh .
davidparks21@192.168.1.15:/tmp/website" -c "expect password:" -c "send
${var}\r" -c "expect" -c "wait"'

The purpose of the above command is to use rsync over ssh, read the password
off STDIN and use it to script the interactive password requirement of ssh
when used under rsync - without the need for insecure key files or leaking
the password on the command line.

Last night I built ANT 1.8.3 off SVN and created the following similar
solution to resounding success using the <sshexec ...> task (again, no
insecure key file, leaked passwords on the command line, or external file
dependencies):

<input message="Enter username for ${website.host}:"
addproperty="host.username" />
<input message="Enter password for ${website.host}:"
addproperty="host.password" />
<sshexec host="${website.host}" trust="true"
         username="${host.username}" password="${host.password}"
         inputstring="${host.password}"
         command='read var; expect -c "spawn sudo chmod u+x
/usr/local/website/bin/start_website" -c "expect ${host.username}:" -c "send
${var}\r" -c "wait"' />


Below I show the ANT task in question (and a couple of debug echo
statements) with the output.

I've tried every form of quoting I can think of, and it won't run from ANT.
Here's my best shot.

Description of the ANT Tasks:
 - The first echo outputs the arg line so it can easily be seen in output
that quotes are resolved properly
 - the exec calls bash and passes it 2 arguments (-c) and
(the_read+expect_commands), the same as is being done in the command line
shown above that works in DOS
 - The output shows nothing from the <exec> command, but ${debug.exec} shows
that something went terribly wrong with the passed arguments. It appears to
have split them even though <arg value=.../> was being used.

I've tried quoting or not quoting the second argument, escaping quotes,
using the deprecated commandline option, and a host of other things related
to the way quotes are presented. All result in the same or worse scenario.

===============
ANT Task
===============
<property name="qq" value='"' />

<echo message='read var;expect -d -c "spawn rsync -aOvz
--chmod=Du=rwx,Dg=rx,Do=rx,Fu=rw,Fg=r,Fo=r -e ssh .
davidparks21@192.168.1.15:/tmp/website" -c "expect password:" -c "send
${var}\r" -c "expect" -c "wait"' />
<message="-------------------------" />
		
<exec executable="${cygwin.dir}\bin\bash.exe" 
	  dir="${production.config.dir}/${versionName}/WEBSERVER" 
	  inputstring="${host.password}" 
	  outputproperty="debug.exec">
	<arg value="-c" />
	<arg value='read var;expect -d -c "spawn rsync -aOvz
--chmod=Du=rwx,Dg=rx,Do=rx,Fu=rw,Fg=r,Fo=r -e ssh .
davidparks21@192.168.1.15:/tmp/website" -c "expect password:" -c "send
${var}\r" -c "expect" -c "wait"' />
	<env key="PATH" path="${cygwin.dir}\bin" />
</exec>

<echo message="-------------------------" />
<echo message="${debug.exec}" />

======================
And the output is:
======================

     [echo] read var;expect -d -c "spawn rsync -aOvz
--chmod=Du=rwx,Dg=rx,Do=rx,Fu=rw,Fg=r,Fo=r -e ssh .
davidparks21@192.168.1.15:/tmp/website" -c "expect password:" -c "send
${var}\r" -c "expect" -c "wait"
     [echo] -------------------------
     [echo] -------------------------
     [echo] expect version 5.26
     [echo] usage: spawn [spawn-args] program [program-args]
     [echo]     while executing
     [echo] "spawn"
     [echo] argv[0] = expect  argv[1] = -d  argv[2] = -c  argv[3] = spawn  
     [echo] set argc 0
     [echo] set argv0 "expect"
     [echo] set argv ""


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


RE: Ant 1.8.3alpha: task fails to handle quotes within quotes command lines

Posted by "Echlin, Robert" <Ro...@windriver.com>.
Hi David,
I can only give you the same message I give other people who come to me in person with a problem and solve it while telling me about it.
"You're welcome. It happens to me, too."
Keep on reading your own posts. And never apologize for a learning tool that works!
:-)

Rob

> -----Original Message-----
> From: David Parks [mailto:davidparks21@yahoo.com]
> Sent: Tuesday, June 28, 2011 12:28 AM
> To: 'Ant Users List'
> Subject: RE: Ant 1.8.3alpha: <exec> task fails to handle quotes within quotes
> command lines
> 
> Why do our brains work in such strange ways? I spent hours on this issue,
> and 40 minutes writing the email and testing every bit of it was correct.
> 
> Now I received my own email, compulsively re-read it, and the answer just
> popped into my head effortlessly.
> 
> Use cmd /C
> 
> Here is a modification of the task that now works using cmd /c to execute the
> cygwin bash command line (hence using the exact command-line handling as
> I experimented with successfully in DOS).
> 
> <property name="q" value="'" />
> <exec executable="cmd"
> 	  dir="${production.config.dir}/${versionName}/WEBSERVER"
> 	  inputstring="${host.password}"
> 	  outputproperty="debug.exec">
> 	<arg value="/C" />
> 	<arg value='${cygwin.dir}\bin\bash.exe -c ${q}read var;expect -d -c
> "spawn rsync -aOvz --chmod=Du=rwx,Dg=rx,Do=rx,Fu=rw,Fg=r,Fo=r -e ssh .
> davidparks21@192.168.1.15:/tmp/website" -c "expect password:" -c "send
> ${var}\r" -c "expect" -c "wait"${q}' />
> 	<env key="PATH" path="${cygwin.dir}\bin" /> </exec>
> 
> I don't quite know how to thank you, I wouldn't have solved it without you,
> but I'm only talking to myself here. I suppose this is natures version of an
> infinite loop.
> 
> 
> 
> -----Original Message-----
> From: David Parks [mailto:davidparks21@yahoo.com]
> Sent: Tuesday, June 28, 2011 10:35 AM
> To: user@ant.apache.org
> Subject: Ant 1.8.3alpha: <exec> task fails to handle quotes within quotes
> command lines
> 
> I'm trying to run a command with both single and double quotes through
> <exec ...>. I am using last nights build of ant 1.8.3alpha (I should note the
> same behavior on 1.8.2). But the arguments appear to be incorrectly passed
> to the command line, as per the following demonstration.
> 
> This command runs from a DOS command line perfectly:
> 
> c:\cygwin\bin\bash.exe -c 'read var;expect -d -c "spawn rsync -aOvz --
> chmod=Du=rwx,Dg=rx,Do=rx,Fu=rw,Fg=r,Fo=r -e ssh .
> davidparks21@192.168.1.15:/tmp/website" -c "expect password:" -c "send
> ${var}\r" -c "expect" -c "wait"'
> 
> The purpose of the above command is to use rsync over ssh, read the
> password off STDIN and use it to script the interactive password requirement
> of ssh when used under rsync - without the need for insecure key files or
> leaking the password on the command line.
> 
> Last night I built ANT 1.8.3 off SVN and created the following similar solution
> to resounding success using the <sshexec ...> task (again, no insecure key
> file, leaked passwords on the command line, or external file
> dependencies):
> 
> <input message="Enter username for ${website.host}:"
> addproperty="host.username" />
> <input message="Enter password for ${website.host}:"
> addproperty="host.password" />
> <sshexec host="${website.host}" trust="true"
>          username="${host.username}" password="${host.password}"
>          inputstring="${host.password}"
>          command='read var; expect -c "spawn sudo chmod u+x
> /usr/local/website/bin/start_website" -c "expect ${host.username}:" -c
> "send ${var}\r" -c "wait"' />
> 
> 
> Below I show the ANT task in question (and a couple of debug echo
> statements) with the output.
> 
> I've tried every form of quoting I can think of, and it won't run from ANT.
> Here's my best shot.
> 
> Description of the ANT Tasks:
>  - The first echo outputs the arg line so it can easily be seen in output that
> quotes are resolved properly
>  - the exec calls bash and passes it 2 arguments (-c) and
> (the_read+expect_commands), the same as is being done in the command
> line shown above that works in DOS
>  - The output shows nothing from the <exec> command, but ${debug.exec}
> shows that something went terribly wrong with the passed arguments. It
> appears to have split them even though <arg value=.../> was being used.
> 
> I've tried quoting or not quoting the second argument, escaping quotes,
> using the deprecated commandline option, and a host of other things related
> to the way quotes are presented. All result in the same or worse scenario.
> 
> ===============
> ANT Task
> ===============
> <property name="qq" value='"' />
> 
> <echo message='read var;expect -d -c "spawn rsync -aOvz --
> chmod=Du=rwx,Dg=rx,Do=rx,Fu=rw,Fg=r,Fo=r -e ssh .
> davidparks21@192.168.1.15:/tmp/website" -c "expect password:" -c "send
> ${var}\r" -c "expect" -c "wait"' /> <message="-------------------------" />
> 
> <exec executable="${cygwin.dir}\bin\bash.exe"
> 	  dir="${production.config.dir}/${versionName}/WEBSERVER"
> 	  inputstring="${host.password}"
> 	  outputproperty="debug.exec">
> 	<arg value="-c" />
> 	<arg value='read var;expect -d -c "spawn rsync -aOvz --
> chmod=Du=rwx,Dg=rx,Do=rx,Fu=rw,Fg=r,Fo=r -e ssh .
> davidparks21@192.168.1.15:/tmp/website" -c "expect password:" -c "send
> ${var}\r" -c "expect" -c "wait"' />
> 	<env key="PATH" path="${cygwin.dir}\bin" /> </exec>
> 
> <echo message="-------------------------" /> <echo message="${debug.exec}"
> />
> 
> ======================
> And the output is:
> ======================
> 
>      [echo] read var;expect -d -c "spawn rsync -aOvz --
> chmod=Du=rwx,Dg=rx,Do=rx,Fu=rw,Fg=r,Fo=r -e ssh .
> davidparks21@192.168.1.15:/tmp/website" -c "expect password:" -c "send
> ${var}\r" -c "expect" -c "wait"
>      [echo] -------------------------
>      [echo] -------------------------
>      [echo] expect version 5.26
>      [echo] usage: spawn [spawn-args] program [program-args]
>      [echo]     while executing
>      [echo] "spawn"
>      [echo] argv[0] = expect  argv[1] = -d  argv[2] = -c  argv[3] = spawn
>      [echo] set argc 0
>      [echo] set argv0 "expect"
>      [echo] set argv ""
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For additional
> commands, e-mail: user-help@ant.apache.org
> 
> -----
> No virus found in this message.
> Checked by AVG - www.avg.com
> Version: 10.0.1388 / Virus Database: 1516/3730 - Release Date: 06/27/11
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For additional
> commands, e-mail: user-help@ant.apache.org


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


RE: Ant 1.8.3alpha: task fails to handle quotes within quotes command lines

Posted by David Parks <da...@yahoo.com>.
Why do our brains work in such strange ways? I spent hours on this issue,
and 40 minutes writing the email and testing every bit of it was correct.

Now I received my own email, compulsively re-read it, and the answer just
popped into my head effortlessly. 

Use cmd /C

Here is a modification of the task that now works using cmd /c to execute
the cygwin bash command line (hence using the exact command-line handling as
I experimented with successfully in DOS).

<property name="q" value="'" />
<exec executable="cmd" 
	  dir="${production.config.dir}/${versionName}/WEBSERVER" 
	  inputstring="${host.password}" 
	  outputproperty="debug.exec">
	<arg value="/C" />
	<arg value='${cygwin.dir}\bin\bash.exe -c ${q}read var;expect -d -c
"spawn rsync -aOvz --chmod=Du=rwx,Dg=rx,Do=rx,Fu=rw,Fg=r,Fo=r -e ssh .
davidparks21@192.168.1.15:/tmp/website" -c "expect password:" -c "send
${var}\r" -c "expect" -c "wait"${q}' />
	<env key="PATH" path="${cygwin.dir}\bin" />
</exec>

I don't quite know how to thank you, I wouldn't have solved it without you,
but I'm only talking to myself here. I suppose this is natures version of an
infinite loop.



-----Original Message-----
From: David Parks [mailto:davidparks21@yahoo.com] 
Sent: Tuesday, June 28, 2011 10:35 AM
To: user@ant.apache.org
Subject: Ant 1.8.3alpha: <exec> task fails to handle quotes within quotes
command lines

I'm trying to run a command with both single and double quotes through <exec
...>. I am using last nights build of ant 1.8.3alpha (I should note the same
behavior on 1.8.2). But the arguments appear to be incorrectly passed to the
command line, as per the following demonstration.

This command runs from a DOS command line perfectly:

c:\cygwin\bin\bash.exe -c 'read var;expect -d -c "spawn rsync -aOvz
--chmod=Du=rwx,Dg=rx,Do=rx,Fu=rw,Fg=r,Fo=r -e ssh .
davidparks21@192.168.1.15:/tmp/website" -c "expect password:" -c "send
${var}\r" -c "expect" -c "wait"'

The purpose of the above command is to use rsync over ssh, read the password
off STDIN and use it to script the interactive password requirement of ssh
when used under rsync - without the need for insecure key files or leaking
the password on the command line.

Last night I built ANT 1.8.3 off SVN and created the following similar
solution to resounding success using the <sshexec ...> task (again, no
insecure key file, leaked passwords on the command line, or external file
dependencies):

<input message="Enter username for ${website.host}:"
addproperty="host.username" />
<input message="Enter password for ${website.host}:"
addproperty="host.password" />
<sshexec host="${website.host}" trust="true"
         username="${host.username}" password="${host.password}"
         inputstring="${host.password}"
         command='read var; expect -c "spawn sudo chmod u+x
/usr/local/website/bin/start_website" -c "expect ${host.username}:" -c "send
${var}\r" -c "wait"' />


Below I show the ANT task in question (and a couple of debug echo
statements) with the output.

I've tried every form of quoting I can think of, and it won't run from ANT.
Here's my best shot.

Description of the ANT Tasks:
 - The first echo outputs the arg line so it can easily be seen in output
that quotes are resolved properly
 - the exec calls bash and passes it 2 arguments (-c) and
(the_read+expect_commands), the same as is being done in the command line
shown above that works in DOS
 - The output shows nothing from the <exec> command, but ${debug.exec} shows
that something went terribly wrong with the passed arguments. It appears to
have split them even though <arg value=.../> was being used.

I've tried quoting or not quoting the second argument, escaping quotes,
using the deprecated commandline option, and a host of other things related
to the way quotes are presented. All result in the same or worse scenario.

===============
ANT Task
===============
<property name="qq" value='"' />

<echo message='read var;expect -d -c "spawn rsync -aOvz
--chmod=Du=rwx,Dg=rx,Do=rx,Fu=rw,Fg=r,Fo=r -e ssh .
davidparks21@192.168.1.15:/tmp/website" -c "expect password:" -c "send
${var}\r" -c "expect" -c "wait"' />
<message="-------------------------" />
		
<exec executable="${cygwin.dir}\bin\bash.exe" 
	  dir="${production.config.dir}/${versionName}/WEBSERVER" 
	  inputstring="${host.password}" 
	  outputproperty="debug.exec">
	<arg value="-c" />
	<arg value='read var;expect -d -c "spawn rsync -aOvz
--chmod=Du=rwx,Dg=rx,Do=rx,Fu=rw,Fg=r,Fo=r -e ssh .
davidparks21@192.168.1.15:/tmp/website" -c "expect password:" -c "send
${var}\r" -c "expect" -c "wait"' />
	<env key="PATH" path="${cygwin.dir}\bin" />
</exec>

<echo message="-------------------------" />
<echo message="${debug.exec}" />

======================
And the output is:
======================

     [echo] read var;expect -d -c "spawn rsync -aOvz
--chmod=Du=rwx,Dg=rx,Do=rx,Fu=rw,Fg=r,Fo=r -e ssh .
davidparks21@192.168.1.15:/tmp/website" -c "expect password:" -c "send
${var}\r" -c "expect" -c "wait"
     [echo] -------------------------
     [echo] -------------------------
     [echo] expect version 5.26
     [echo] usage: spawn [spawn-args] program [program-args]
     [echo]     while executing
     [echo] "spawn"
     [echo] argv[0] = expect  argv[1] = -d  argv[2] = -c  argv[3] = spawn  
     [echo] set argc 0
     [echo] set argv0 "expect"
     [echo] set argv ""


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

-----
No virus found in this message.
Checked by AVG - www.avg.com
Version: 10.0.1388 / Virus Database: 1516/3730 - Release Date: 06/27/11


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