EXEC task with '|' in the arguments - ant

I'm trying to exec a VS build using incredibuild within my ANT script, but For some reason the exec task fails with the following error:
'Win32' is not recognized as an internal or external command
when I use the following code:
<arg line='buildconsole solution.sln /rebuild /cfg="Release|Win32"' />
I think the ant script may be treating the '|' as a delimter or something...
Any ideas how I could get this to work?
I've also tried the following, but nothing gets me closer:
<arg line='buildconsole solution.sln /rebuild /cfg="Release|Win32"' />
<arg value="buildconsole solution.sln /rebuild /cfg="Release|Win32"" />
<arg value="buildconsole solution.sln /rebuild /cfg="Release|Win32"" />

You need to escape the pipe symbol by preceding it with ^. So:
<arg line='buildconsole solution.sln /rebuild /cfg="Release^|Win32"' />
EDIT:
Are you sure the caret doesn't work? It seems to in this sample ant file:
<?xml version="1.0" encoding="UTF-8"?>
<project name="Test" default="build" basedir=".">
<target name="build">
<exec executable="cmd">
<arg line="/k echo cfg="Release^|Win32""/>
</exec>
</target>
</project>

Hmm... I just tried it again and it worked, but only after I changed to
<arg value="buildconsole solution.sln /rebuild /cfg=Release^|Win32" />
so I guess the quotes around Release^|Win32 wasn't necessary if I use value.
Thanks a bunch!

I think the problem is that the Windows command prompt sees the | and treats it as a "pipe" operator. Perhaps escape the pipe by using:
<arg line='buildconsole solution.sln /rebuild /cfg="Release\|Win32"' />

Related

Fitnesse SymbolicLink not working with external link from ant or command line

We are trying to create a symbolic link in our fitnesse suite to an external folder. It is working perfectly with URL. But not working with command line or with ant script.
Following is the URL (Working):
http://localhost:8080/root?responder=symlink&linkName=FitNesseSuite&linkPath=file://FitNesseRoot/TestSuite
Command line (Not working):
java -jar fitnesse.jar -c "root?responder=symlink&linkName=FitNesseSuite&linkPath=file://FitNesseRoot/TestSuite"
Ant script (Not working):
<target name="my_fitnesse_tests">
<java jar="fitnesse.jar" failonerror="true" fork="true">
<arg value="-c" />
<arg value="root?responder=symlink&linkName=FitNesseSuite&linkPath=file://FitNesseRoot/TestSuite" />
<arg value="-p" />
<arg value="9234" />
</java>
</target>
Getting following exception:
Exception in thread "main" java.lang.IllegalArgumentException: Command
specification
[root?responder=symlink&linkName=FitNesseSuite&linkPath=file://FitNesseRoot/TestSuite]
invalid. Format shold be /cmd or user:pass:/cmd at
fitnesse.http.MockRequestBuilder.validate(MockRequestBuilder.java:48)
Please help us to solve this.
Same problem, I have solve the problem with the following command:
...&linkPath=file%3A///... ==> change the ":" by "%3A"

Trouble passing argument to Ant exec task

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.

Executing command line code in an ant build file

How can I execute following command line code in an ant build file?
cd backend/doctrine/
export PC_ZEND_ENV=testing
php doctrine migrations:migrate << EOF
y
EOF
The solution
With the feedback I've got I figured out the following working exec command.
<exec dir="backend/doctrine" executable="php">
<env key="PC_ZEND_ENV" value="development" />
<arg line="doctrine migrations:migrate" />
<arg value="<< Y" />
</exec>
Use the exec task. The result should be something like the following (untested):
<exec dir="backend/doctrine" executable="./doctrine">
<arg line="migrations:migrate << EOF"/>
<env key="PC_ZEND_ENV" value="testing"/>
</exec>

How can I execute a VBScript file from Ant script?

I want to run a VBScript file from an Ant script. How can I do that?
Have a look at the exec task. It allows you to execute a system command from your Ant script.
EDIT:
An example could be:
<target name="RunVbScript">
<exec executable="cscript">
<arg value="MyScript.vbs"/>
<arg value="argument 1" />
<arg value="argument 2" />
<arg value="argument n" />
</exec>
</target>

How can I get current PID from within Ant?

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"

Resources