Reputation: 21
I am trying to call the logoff command from my build.xml. I tried several combinations in my ant target such as :
<target name="bat">
<echo>Executing batch script</echo>
<exec dir="C:\WINDOWS\system32" executable="cmd">
<arg value="/c"/>
<arg value="logoff"/>
</exec>
</target>
But everytime, I get this error : "logoff is not recognized as an internal or external command, operable program or batch file"
I don't know how to fix this issue. Thanks for helping.
EDIT:
logoff.xml
<?xml version="1.0"?>
<project name="logoff" default="off" basedir=".">
<target name="off">
<exec executable="cmd">
<arg value="/c"/>
<arg value="logoff"/>
</exec>
</target>
</project>
logoff_xml.bat:
@echo off
set ANT_HOME=W:\lib\org.apache.ant
set JAVA_HOME=C:\Program Files (x86)\Java\jdk1.6.0_24
set PATH=%PATH%;%ANT_HOME%\bin
set BUILD_PATH=W:\logoff.xml
set ANT=call ant -buildfile %BUILD_PATH%
%ANT%
pause
echo %PATH% (with buid.xml bat target)
[exec] C:\Outils\GPS_510\bin;C:\Outils\GNATPRO_6.1.2\bin;C:\WINDOWS\system3
2;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Outils\Python25;C:\MinGW\bin;C:\Program
Files (x86)\IBM\RationalSDLC\common;C:\Program Files (x86)\IBM\RationalSDLC\Cle
arCase\bin;C:\Program Files (x86)\doxygen\bin;C:\Program Files (x86)\Citrix\Syst
em32\Citrix\IMA;C:\Program Files (x86)\Citrix\System32\Citrix\IMA\Subsystems;C:\
WINDOWS\System32\Citrix\IMA;C:\Program Files (x86)\Citrix\system32;C:\Program Fi
les (x86)\commonfiles\Citrix\System32\;C:\MinGW\msys\1.0\bin;c:\outils\cygw
in\bin;C:\WINDOWS\system32\WindowsPowerShell\v1.0;C:\Program Files (x86)\commonfiles
\Citrix\System32;C:\Program Files (x86)\Java\jre6\bin;lib\org.apache.an
t\bin
EDIT : When I launch logoff with Ant, I got :
[exec] Disconnecting
[exec] "logoff.exe is not recognized as an internal or external command, operable program or batch file"
Upvotes: 0
Views: 436
Reputation: 7924
I cannot possibly imagine why anyone would ever do this in a build script.
Please don't do this.
But if you do, don't exec cmd.exe
- call logoff.exe
directly
<project name="logoff" default="logoff" basedir=".">
<target name="logoff">
<exec executable="logoff" />
</target>
</project>
It's a very safe assumption that logoff.exe
is on %PATH%
, if for some reason it's not, set a property to get the absolute path to logoff.exe
;
<project name="logoff" default="logoff" basedir=".">
<property name="system32.dir" location="C:\Windows\System32" />
<target name="logoff">
<exec executable="${system32.dir}\logoff" />
</target>
</project>
I feel dirty for having typed this.
Upvotes: 1
Reputation: 4579
You should remove that dir atribute.... This is working for me:
<?xml version="1.0" encoding="UTF-8" ?>
<project name="logoff" default="default" basedir=".">
<target name="default">
<exec executable="cmd">
<arg value="/c"/>
<arg value="logoff"/>
</exec>
</target>
</project>
EDIT:
@echo off
set ANT_HOME=W:\lib\org.apache.ant
set PATH=%PATH%;%ANT_HOME%\bin
set BUILD_PATH=W:\logoff.xml
set ANT=call ant -buildfile %BUILD_PATH%
%ANT%
pause
Upvotes: 0
Reputation: 3701
Try using shutdown /l /f
instead, as suggested here:
This might also help (description how to do it in java) as ant uses similar (to java) arguments:
Upvotes: 0