Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从Ant中获取当前PID?_Ant - Fatal编程技术网

如何从Ant中获取当前PID?

如何从Ant中获取当前PID?,ant,Ant,我有一个ant任务,我想在其中获取当前进程id(从命令行获取laecho$PPID) 我正在Solaris上运行ksh,所以我想我可以这样做: <property environment="env" /> <target name="targ"> <echo message="PID is ${env.PPID}" /> <echo message="PID is ${env.$$}" /> </target> get

我有一个ant任务,我想在其中获取当前进程id(从命令行获取la
echo$PPID

我正在Solaris上运行
ksh
,所以我想我可以这样做:

<property environment="env" />
<target name="targ">
    <echo message="PID is ${env.PPID}" />
    <echo message="PID is ${env.$$}" />
</target>
getpid.sh
如下所示:

echo $$
这将获得生成的shell脚本的PID。更近,但不是我真正需要的


我只需要我当前的进程ID,这样我就可以在名称中使用该值创建一个临时文件。有什么想法吗?

为什么不直接使用
tempfile
Ant任务呢?它做你真正想做的事,同时隐藏所有血淋淋的细节


请参阅。

您的第二个方法没有获得ANT的pid。将shell脚本更改为(我使用bash,不知道ksh是否相同):


您可以使用java流程监控工具JPS找到PID,然后可以过滤输出流,并在需要时终止流程。查看这个tomcat pid kill脚本:

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


JPS只提供任何java进程的进程Id。如何处理非java进程。。示例如何在“C:\test\bin”路径上找到cmd.exe进程ID这就像一个符咒。你不一定要通过-l考试。它可以使您的搜索和替换更容易。
echo "$PPID"
<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>