Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.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
Bash ant:列出进程的目标_Bash_Unix_Ant - Fatal编程技术网

Bash ant:列出进程的目标

Bash ant:列出进程的目标,bash,unix,ant,Bash,Unix,Ant,我已经在ant中完成了一些基本的目标,现在我正在尝试做一些更基本的事情 我的目标是有一个“调试”的目标,在这里我可以只获得对ps命令的特定调用的结果 例如,如果我手动调用bash: $ ps -ef | grep /bin/bash 502 1373 1 0 05:28 ? 00:00:00 /bin/bash MyScript.sh /data/dir > MyScript.log 502 32314 31196 0 09:42 pts/

我已经在ant中完成了一些基本的目标,现在我正在尝试做一些更基本的事情

我的目标是有一个“调试”的目标,在这里我可以只获得对ps命令的特定调用的结果

例如,如果我手动调用bash:

$ ps -ef | grep /bin/bash
502       1373     1  0 05:28 ?        00:00:00 /bin/bash MyScript.sh /data/dir  > MyScript.log
502      32314 31196  0 09:42 pts/0    00:00:00 grep /bin/bash
我正在尝试一个基本的目标,这似乎不起作用

  <target name="list-processes" depends="init">
        <exec executable="ps" spawn="false" output="Yes">
           <arg line=" -ef | grep /bin/bash" />
        </exec>
  </target>
我知道我得到的是一个错误,但是如果我在没有参数的情况下运行,它将不会返回任何内容,不是0或1,也不是nothing

编辑2: 我离我想要的东西有点近了,但仍然不在那里

  <target name="list-processes" depends="init">
    <exec executable="ps" osfamily="unix" outputproperty="list-processes-output" resultproperty="list-processes-result">
      <arg line="-ef" />
    </exec>
    <echo message="exec ps result: ${list-processes-result}" />
    <exec executable="grep" osfamily="unix" outputproperty="grep-processes-output" resultproperty="grep-processes-result">
      <arg line="bash" />
    </exec>
    <echo message="${grep-processes-output}" />
    <echo message="exec grep result: ${grep-processes-result}" />
  </target>
这是最终目标

  <target name="list-processes" depends="init">
    <exec executable="ps" osfamily="unix" outputproperty="list-processes-output" resultproperty="list-processes-result">
      <arg line="-ef" />
    </exec>
    <echo message="exec ps result: ${list-processes-result}" />
    <echo message="${list-processes-output}" file="processes.txt"/>
    <exec executable="grep" osfamily="unix" outputproperty="grep-processes-output" resultproperty="grep-processes-result">
      <arg line="/bin/bash processes.txt" />
    </exec>
    <echo message="${grep-processes-output}" />
    <echo message="exec grep result: ${grep-processes-result}" />
  </target>

这是一个Ant脚本,它运行
ps
,然后使用
过滤器“grep”输出:

<project name="ant-exec-ps-grep" default="run">
    <target name="run">
        <exec executable="ps">
            <arg value="-ef"/>
            <redirector outputproperty="list-processes-output">
                <outputfilterchain>
                    <linecontains>
                        <contains value="/bin/bash"/>
                    </linecontains>
                </outputfilterchain>
            </redirector>
        </exec>
        <echo>list-processes-output: ${list-processes-output}</echo>
    </target>
</project>

列表进程输出:${list processs output}
此脚本只启动一个进程(
ps
),而不是两个进程(
ps
grep
),因此此脚本将更快。此外,脚本不会生成任何需要清理的临时文件

  <target name="list-processes" depends="init">
    <exec executable="ps" osfamily="unix" outputproperty="list-processes-output" resultproperty="list-processes-result">
      <arg line="-ef" />
    </exec>
    <echo message="exec ps result: ${list-processes-result}" />
    <echo message="${list-processes-output}" file="processes.txt"/>
    <exec executable="grep" osfamily="unix" outputproperty="grep-processes-output" resultproperty="grep-processes-result">
      <arg line="/bin/bash processes.txt" />
    </exec>
    <echo message="${grep-processes-output}" />
    <echo message="exec grep result: ${grep-processes-result}" />
  </target>
<project name="ant-exec-ps-grep" default="run">
    <target name="run">
        <exec executable="ps">
            <arg value="-ef"/>
            <redirector outputproperty="list-processes-output">
                <outputfilterchain>
                    <linecontains>
                        <contains value="/bin/bash"/>
                    </linecontains>
                </outputfilterchain>
            </redirector>
        </exec>
        <echo>list-processes-output: ${list-processes-output}</echo>
    </target>
</project>