I am using:
<exec executable="cmd">
<arg line="${argLine}" />
</exec>
when argLine
<property name="argLine" value="http://127.0.0.1:/product/findSameStyleSku.json?skuId=305&style=120662"/>
with 2 params ,and i use & escape & symbols
but only open http://127.0.0.1/product/findSameStyleSku.json?skuId=305
the style param lost
In short,i want run
<target name="111test">
<exec executable="cmd" output="e:/test.txt">
<arg line="/c start '' 'http://127.0.0.1/product/findSameStyleSku.json?skuId=305&%3bstyle=120662'" />
</exec>
</target>
2012-05-23 update
Yes,Windows system
I change code to
<target name="111test">
<exec executable="cmd" output="e:/test.txt">
<arg value="/c" />
<arg value="start" />
<arg value="" />
<arg value="http://127.0.0.1/product/findSameStyleSku.json?skuId=305&%3bstyle=120662" />
</exec>
</target>
run ant
only open
http://127.0.0.1/product/findSameStyleSku.json?skuId=305
I change "&%3b" to "&"
also only open
http://127.0.0.1/product/findSameStyleSku.json?skuId=305
But in cmd, i use
start "" "http://127.0.0.1/product/findSameStyleSku.json?skuId=305&style=120662"
can open http://127.0.0.1/product/findSameStyleSku.json?skuId=305&style=120662
Not exactly understanding what it's trying to open. Is it literally trying to open a URL with ***?skuId=305, or are you trying to say it's trying to open the URL you gave it up to, but not including the semicolon?
If you are saying that it is leaving off the last part of your URL, you should understand that semicolons cannot be part of the actual URL you're sending. They're reserved and must be specially encoded.
Make sure that semicolon is even suppose to be there. When you do a GET request, you have the basic URL, and then after that URL a question mark. After that, you have a series of parameters you're passing to the URL with each parameter separated by ampersands. In your case, it looks like you want to send a request to URL:
http://127.0.0.1:/product/findSameStyleSku.json
With the following two parameters:
skuId = 305
style = 120662
So, it looks like the semicolon is bogus. Otherwise, you're passing the parameter ;style and not style. And, that doesn't seem it would be correct.
If you've determined that the semicolon is really suppose to be there, try replacing the semicolon in the URL with %3b:
<property name="argLine" value="http://127.0.0.1:/product/findSameStyleSku.json?skuId=305&%3bstyle=120662"/>
Response
,i'm sorry ,it does't Work correctly,I updated my question – feeling
Unfortunately, since this is on a Windows machine, and is something running locally on your machine, I can't run a test myself.
However, according to the first part of your post, you are attempting to run the following command:
C> cmd http://127.0.0.1:/product/findSameStyleSku.json?skuId=305&style=120662
Later in your post, you say you want to run:
C> cmd /c start '' 'http://127.0.0.1/product/findSameStyleSku.json?skuId=305&%3bstyle=120662'
The first certainly won't work from the command line. Does the second one?
I've done a few tests on my current computer using this:
<property name="argLine"
value="http://etzahaim.org/index.php?option=com_content&task=blogcategory&id=15&Itemid=34"/>
<exec executable="curl">
<arg value="${argLine}"/>
<arg value="--include"/>
<arg value="--output"/>
<arg value="curl.out"/>
</exec>
This is the curl command which fetches the URL. This URL is also uses a GET method, so it also has a question mark and some asterisks in the URL. This works for me.
Try switching from <arg line='start' '' 'http://...> to using <arg line> and see if that helps:
<target name="111test">
<exec executable="cmd" output="e:/test.txt">
<arg value="/c"/>
<arg value="start"/>
<arg value=""/>
<arg value="${argline}" />
</exec>
Related
Why can't I set property like this in Apache Ant?
<property name="checker" value="php ${basedir}/vendor/code-checker/src/cc.php" />
And then exec it like this
<exec executable="${checker}">
<arg value="-d" />
<arg path="${basedir}/src" />
</exec>
Instead I have to specify whole path with that scripts' interpreter each time I want to use that checker
<exec executable="php">
<arg value="vendor/code-checker/src/cc.php" />
<arg value="-d" />
<arg path="${basedir}/src" />
</exec>
You can either use executable for the executable you want to run (php in this case) and arg for its arguments, or you can specify the command and all its arguments in a single space-separated attribute
<exec command="${checker} -d ${basedir}/src"/>
You can't mix and match the two. And note that the command form will not work if the basedir contains spaces. If there's any chance of an individual argument containing spaces then there's no choice, you must use the executable and arg form.
Want to replace value in a txt file on macos using ant.
I used the following code, but its giving error: "The type doesn't support nested text data (" ")".
<exec executable="sed">
<arg value="s/old/new/g" />
<arg value="$MY_FILE" />
</exec>.
How to replace a value of an variable, I used replace for a file on windows, it works.
Maybe it's a bit late, but I just found this question. Hopefully, my solution helps at least other people.
There is one parameter missing. sed on the commandline needs either -e "your expression" of -f "/path/to/your scriptfile". In case of ant usage, you want to change the file directly ("internally" in sed's speech), instead of different input / output files. So you need to add -i (or easier, change the -e to -ie).
So, the correct invocation will be:
<exec executable="sed">
<arg value="-ie" />
<arg value="s/old/new/g" />
<arg value="$MY_FILE" />
</exec>
Maybe this can help
ant-contrib PropertyRegex
Performs regular expression operations on an input string, and sets the results to a property
http://ant-contrib.sourceforge.net/tasks/tasks/propertyregex.html
In my case I do not need to change my source file, and i need to change some paths into my log4j.properties. So here is my solution
<exec executable="sed">
<arg value="s-/path/to/change/in/log4j_file-/new/path-g"/>
<arg line="./src/log4j.properties"/>
<redirector output="./output/path/conf/log4j.properties" ></redirector>
</exec>
It is like this command:
sed 's-/path/to/change/in/log4j_file-/new/path/log-g' ./src/log4j.properties > ./output/path/conf/log4j.properties
I am just stuck at thing scenario,
I have a batch file which upon running will ask for confirmation like " press y/n ". Now i am to automate that batch file using ant. so, my code looks something like this
<exec executable="cmd.exe" dir="${base.dir}" >
<arg line="/c run.bat" />
</exec>
but I have no idea how to pass the keyboard value 'y' to it in run time
please help me out
Use the input task?
Use combination of input task and inputstring parameter of exec task.
<input
message="All data is going to be deleted from DB continue (y/n)?"
validargs="y,n"
addproperty="do.delete"
/>
<exec
executable="cmd.exe"
dir="${base.dir}"
inputstring="${do.delete}"
>
<arg line="/c run.bat" />
</exec>
Just provide /y input as you would without ant:
<exec executable="cmd.exe" dir="${base.dir}" >
<arg line="/c run.bat /y "/>
</exec>
Another way is to use inputstring task.
E.g.:
<exec executable= "run.bat" failonerror="true" inputstring="Y">
</exec>
However this proved to be unstable in some scenarios.
I'm using Ant 1.8. I want to pass a property that I define in my script to an exec command. Although I can see the property has a value in my echo statements, when I pass it to the script and output its value in the script, its value prints out as "${myco.test.root}", without being converted. What is the correct way to pass the property's value to the script? Below is the relevant code from my build.xml file …
<target name="checkout-selenium-tests" depends="set-critical-path-test-suite,set-default-test-suite,check-local-folders-exist">
<echo message=" test root ${myco.test.root}" />
<stcheckout servername="${st.servername}"
serverport="${st.serverport}"
projectname="${st.myco.project}"
viewname="${st.myco.viewname}"
username="${st.username}"
password="${st.password}"
rootstarteamfolder="${myco.starteam.test.root}"
rootlocalfolder="${myco.test.root}"
forced="true"
deleteuncontrolled="true"
/>
<delete file="${myco.testsuite.file}" />
<echo message="test root ${myco.test.root}" />
<exec failonerror="true" executable="perl" dir="${scripts.dir}">
<arg value="generate_test_suite.pl" />
<arg value="My Tests" />
<arg value="${myco.test.root}" />
<arg value="${myco.testsuite.file}" />
</exec>
</target>
Thanks, - Dave
It actually looks good to me. Try running the build.xml with both the verbose and debug options turned on in Ant:
ant -d -v checkout-selenium-tests
That'll help trace down where the error could be coming from.
I have an ant task, and within it I'd like to get the current process id (a la echo $PPID from command line).
I'm running ksh on Solaris, so I thought I could just do this:
<property environment="env" />
<target name="targ">
<echo message="PID is ${env.PPID}" />
<echo message="PID is ${env.$$}" />
</target>
But that didn't work; the variables aren't substituted. Turns out PPID, SECONDS, and certain other env variables don't make it into Ant's representation.
Next I try this:
<target name="targ">
<exec executable="${env.pathtomyfiles}/getpid.sh" />
</target>
getpid.sh looks like this:
echo $$
This gets me the PID of the spawned shell script. Closer, but not really what I need.
I just want my current process ID, so I can make a temporary file with that value in the name. Any thoughts?
You can find PID using java process monitoring tool JPS, then output stream can be filtered and if needed process can be killed. check out this tomcat pid kill script:
<target name="tomcat.kill" depends="tomcat.shutdown">
<exec executable="jps">
<arg value="-l"/>
<redirector outputproperty="process.pid">
<outputfilterchain>
<linecontains>
<contains value="C:\tomcat\tomcat_node5\bin\bootstrap.jar"/>
</linecontains>
<replacestring from=" C:\tomcat\tomcat_node5\bin\bootstrap.jar"/>
</outputfilterchain>
</redirector>
</exec>
<exec executable="taskkill" osfamily="winnt">
<arg value="/F"/>
<arg value="/PID"/>
<arg value="${process.pid}"/>
</exec>
<exec executable="kill" osfamily="unix">
<arg value="-9"/>
<arg value="${process.pid}"/>
</exec>
</target>
Why not just use the tempfile Ant task, instead? It does what you really want to do, while hiding all the gory details.
See http://ant.apache.org/manual/Tasks/tempfile.html.
your second method doesn't get ANT's pid. Change the shell script to (I use bash, I don't know if ksh is the same):
echo "$PPID"