1

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:

  • Send the command that creates a background work (thread)
  • while the background work is being accomplished, I should be able to close the session/connection with the intention of the background work continuing

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

0

1 Answer 1

1

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 &");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.