0

I want to control status of my Tomcat server from ASP.NET. So basically I execute the following commands:

sudo /etc/rc.d/init.d/tomcat5_3 status
sudo /etc/rc.d/init.d/tomcat5_3 stop
sudo /etc/rc.d/init.d/tomcat5_3 start

I use a simple call of method Session.ExecuteCommand from WinSCP .NET assembly like below:

public string ExecScript(string cmd)
{
    try
    {
        CommandExecutionResult result = sessDB.ExecuteCommand(cmd);
        result.Check();
        return result.Output;
    }
    catch (Exception e)
    {
        Console.WriteLine("An error occurred: '{0}'", e);
    }
    return "";
}

I call ExecScript with one of these three commands:

string result = ExecScript("sudo /etc/rc.d/init.d/tomcat5_3 status");

The status command works fine. Always return a string so I am able to parse it and get a correct status of Tomcat.

But when I try to stop/start result should be something like below:

1st message

Stopping tomcat:            

2nd part of message after a few seconds

Stopping tomcat:            [OK]

and then problem appears. Program of course does not show these messages, it just hangs, output window returns code 259 which as I know means "command still in progress".

In fact stop/start operation finishes with success. But my app does not inform me about it. No error, no exception, hung ...

Any hints, advices?

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
user3863616
  • 185
  • 1
  • 9
  • 24
  • 1
    So does the `Session.ExecuteCommand` hang or return 259? It cannot do both. – Martin Prikryl Dec 15 '15 at 11:40
  • code 259 appears in output window of VS. I guess it can come from IISExpress. Execute command hangs. Your suggestion about background/foreground seems to be a good direction. :) – user3863616 Dec 15 '15 at 11:45

0 Answers0