ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "David Parks" <davidpark...@yahoo.com>
Subject RE: Ant 1.8.3alpha: <exec> task fails to handle quotes within quotes command lines
Date Tue, 28 Jun 2011 04:28:27 GMT
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


Mime
View raw message