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_Ant - Fatal编程技术网

以不同的用户身份运行ant

以不同的用户身份运行ant,ant,Ant,如果我以root用户身份运行任务,是否有方法检测其以root用户身份运行,并以其他用户身份运行某些任务 我有某些任务需要以root用户身份运行,而其他任务则只需要以当前用户身份运行。如果当前用户具有特定名称,例如“root”,则可以使用以下类似的方法来运行某些目标 <condition property="rootTasksEnabled"> <equals arg1="${user.name}" arg2="root" /> </condition>

如果我以root用户身份运行任务,是否有方法检测其以root用户身份运行,并以其他用户身份运行某些任务


我有某些任务需要以root用户身份运行,而其他任务则只需要以当前用户身份运行。

如果当前用户具有特定名称,例如“root”,则可以使用以下类似的方法来运行某些目标

<condition property="rootTasksEnabled">
    <equals arg1="${user.name}" arg2="root" />
</condition>

<target name="do-stuff-if-root" if="rootTasksEnabled">
    <echo>Doing root stuff</echo>
</target>

做根的东西
至于以不同用户的身份运行Ant,您可以使用with su命令生成另一个Ant进程:

<target name="do-stuff" depends="do-stuff-if-root, do-other-stuff" />

<condition property="rootTasksEnabled">
    <equals arg1="${user.name}" arg2="root" />
</condition>
<property name="targetToRunAsOtherUser" value="do-stuff-as-other-user" />
<property name="otherUser" value="johnny" />

<target name="do-stuff-if-root" if="rootTasksEnabled">
    <echo>Doing root stuff</echo>

    <exec executable="su">
        <arg value="-c" />
        <arg value="${ant.home}/bin/ant -buildfile ${ant.file} ${targetToRunAsOtherUser}" />
        <arg value="${otherUser}" />
    </exec>
</target>

<target name="do-other-stuff">
    <echo>Doing normal build stuff</echo>
</target>

<target name="do-stuff-as-other-user">
    <echo>I am running as ${user.name}</echo>
    <echo>My home is ${user.home}</echo>
</target>

做根的东西
做正常的构建工作
我以${user.name}的身份运行
我家是${user.home}
此示例仅适用于Unix。要在Windows中执行此操作,您可能需要使用runas命令而不是su