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
Related
I can run the following terminal command just fine:
security cms -D -i ../MyMobileProvision.mobileprovision > provision.plist
However, when I run it in Ant, from an ant script in the exact same directory, terminal claims the provisioning file doesn't exist and it creates an empty file for provision.plist, which screws up the next step in my process. The ant code looks like this:
<exec executable="security">
<arg line="cms -D -i ../MyMobileProvision.mobileprovision > provision.plist" />
</exec>
Am I missing something about how ant works? I'm no expert at build scripts but I can use ../ syntax to import properties files just fine, so I'm confused why a relative path isn't working for a terminal command that otherwise would work fine with it.
In your terminal command example, the snippet...
> provision.plist
...is interpreted by your shell as a redirect command.
The <exec> task of Ant doesn't use a shell to execute commands. Instead, the > provision.plist is passed unmodified to the security program.
To get what you want, use the output attribute of <exec>. output is the name of a file where <exec> will write the output:
<exec executable="security" output="provision.plist">
<arg value="cms" />
<arg value="-D" />
<arg value="-i" />
<arg value="../MyMobileProvision.mobileprovision" />
</exec>
In the above example, I've replaced the <arg line="..."> with several <arg value="..."> elements. The reasoning from the Ant documentation on Command-line Arguments:
It is highly recommended to avoid the line version when possible. Ant will try to split the command line in a way similar to what a (Unix) shell would do, but may create something that is very different from what you expect under some circumstances.
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.
What I want to do is:
<exec executable="thrift" dir="${thriftsrc}">
<arg value="--gen java"/>
<arg value="-out ${src}"/>
<arg value="mqlServer.idl"/>
</exec>
I have copied thrift.exe in C:\Windows\System32\ so the file is definitely in the PATH. I have tried several executable Arguments, full path, with and without .exe but it is not working in any variant.
But this is working very well:
<exec executable="perl" dir="${generators}">
<arg value="compactTalib.pl"/>
<arg value="${talibsrc}"/>
</exec>
Any Ideas how I can get my thirft compiler invoked in my ant build?
First, go to a DOS prompt and type in "thrift". Does it "work"? I'd expect it to give you an error, but at least find the exe. If it doesn't find the exe, solve that problem before going back to Ant.
Second, echo ${thriftsrc} in Ant. Is that C:\Windows\System32? If not, omit the dir argument. It's optional so you might remove it anyway and just use the path.
Finally, I see another problem that you haven't hit yet. This is going to get passed in as a single parameter "--gen java".
<arg value="--gen java"/>
The relevant part of the doc is:
is a single command-line argument containing a
space character, not separate commands "-l" and "-a".
This is likely how the thrift command should be called:
<exec executable="thrift" dir="${thriftsrc}">
<arg value="--gen"/>
<arg value="java"/>
<arg value="-out"/>
<arg value="${src}"/>
<arg value="mqlServer.idl"/>
</exec>
Also, consider adding failonerror to your <exec> task:
<exec executable="thrift" dir="${thriftsrc}" failonerror="yes">
This will cause the Ant script to end with an error message which will help with troubleshooting.
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>
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.