tags:

views:

770

answers:

2

I have an ant task, and within it I'd like to get the current process id (a la "echo $PPID" from commmand 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?

+2  A: 

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/CoreTasks/tempfile.html.

Brian Clapper
+1  A: 

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"
jscoot