But what if the program you want to run is interactive? That is, it prompts for input and won't let you pass in arguments from the command-line (or, its insecure to pass it in on the command line, like a password). Well, unfortunately we can't get the interactivity to show up in Ant (it's a design decision-- I'm not totally clear on why, but it has to do with reliably being able to know when the child process is done.)
So we have to pipe the input in. Using the "inputstring" attribute we can do this. (And using the "input" task, you can prompt for things in Ant and then pass them on to the exec task using inputstring.)
But what about multiple arguments? e.g., where the user would hit <enter>?
This stumped me for a bit (there's a dearth of exec and inputstring examples on the web) until I realized that we need to encode the <enter> into the inputstring ourselves. But how? '\n' doesn't mean anything to Ant.
But we can encode the ASCII code for '\n' as an XML entity. The ASCII code for '\n' is 0x0A, so we use "
".
Like, so:
<!-- Line-Feed (LF or '\n') -->
<property name="LF" value="
" />
<!-- arguments to feed into exec -->
<property name="username" value="joeschmoe" />
<property name="password" value="blahblah" />
<exec executable="${myprog}" failonerror="true" inputstring="${username}${LF}${password}${LF}">
<arg value="lalala" />
</exec>
2 comments:
Thanks a lot, it helped me.
Thanks. It helped me while I was stumped by a dialog pop-up warning me about potential size of the archive. Luckily the default focus was set on OK button. Hence all I needed was to press an Enter via ant inputstring.
-Shekhar
Post a Comment