views:

26

answers:

1

Hi!

I want to start and stop a tomcat server on a remote windows machine. I want to be able to do this from an ant script (so our build server can do this).

I wasn't able to get this solved using sc.exe, because there is no way to pass username and password to the remote machine.

Instead I'm using psexec to run commands on the remote server. My ant script looks like this:

<target name="start_tomcat_server">
    <exec executable="psexec.exe" failonerror="true">
        <arg value="/accepteula"/>
        <arg value="\\test_host"/>
        <arg value="-u"/>
        <arg value="username"/>
        <arg value="-p"/>
        <arg value="password"/>
        <arg value="net"/>
        <arg value="start"/>
        <arg value="tomcat6"/>
    </exec>
</target>

If I run this command from the command prompt, everything works fine:
psexec.exe /accepteula \\test_host -u username -p password net start tomcat6

But, when I run the ant target, the psexec process never terminates, it just hangs with this output:

start_tomcat_server:
     [exec]
     [exec] PsExec v1.98 - Execute processes remotely
     [exec] Copyright (C) 2001-2010 Mark Russinovich
     [exec] Sysinternals - www.sysinternals.com
     [exec]

Any ideas what I can do to make this work?

A: 

After spending some more time, I found a solution for this. Give the parameter '-d' to psexec and it will detach from standard out.

        ...
        <arg value="-d"/>
        ...

One thing to note, when adding '-d', psexec returns the PID of the started process and not 0, so ant will think the command failed.

lagurz