Samuel
Samuel

Reputation: 113

Execute command with SSH.NET without blocking and keep it running after closing the connection

I'm using the following code:

using (var client = new SshClient(host, user, pass))
{
    client.Connect();

    var terminal = client.RunCommand("/home/my-script.sh");
}

The client.RunCommand hangs because the command I'm using is creating a thread. I'd like the command to be executed and not wait for the thread to be finished. How would I dot it?

So to sum up, I want to:

Reference: https://csharp.hotexamples.com/examples/Renci.SshNet/SshClient/RunCommand/php-sshclient-runcommand-method-examples.html

Upvotes: 1

Views: 3124

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202088

This is not really SSH.NET question, but rather a generic SSH/shell question.

See How to make a program continue to run after log out from ssh?

So this should do:

client.RunCommand("nohup /home/my-script.sh > foo.out 2> foo.err < /dev/null &");

Upvotes: 1

Related Questions