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-unsubscr...@ant.apache.org
For additional commands, e-mail: user-h...@ant.apache.org

Reply via email to