goph
goph copied to clipboard
How can I escape ```client.Run(cmd)``` loop?
Question: How can I escape the client.Run(cmd)
loop?
When I call client.Run(cmd)
or cmd.Execute(myCmd)
my program can't go to the next tasks.
I am trying to run the command in the background of the remote host. then Close connection and allow the app to do other things.
defer sshClient.Close() // The app cannot close this
_, _:= sshClient.Run(myCmd + "&") // Infinite loop.
someEsleTasks() // The app cannot execute this line
Currently I'm skipping Runc(cmd)
and jumping to the next code via goroutine. like this
go func() {
_, _:= sshClient.Run(myCmd + "&") // Infinite loop.
sshClient.Close() // The app cannot execute this line
}()
I'm looking for a logical solution to my problem. thank you so much
Hi,
go routines is a good way to do it, without "&" at the end of cmd.
Yes. This is a temporary solution. The remote application will remain running as long as my application is running. When my app stops the remote app will stop. I'm still looking for a good solution to the problem. Another solution is to use SystemD It is a good solution. But I avoid it for technical reasons.
Yes. This is a temporary solution. The remote application will remain running as long as my application is running. When my app stops the remote app will stop. I'm still looking for a good solution to the problem. Another solution is to use SystemD It is a good solution. But I avoid it for technical reasons.
Hi! Have you found any good solution of this problem?
I think that nohup
it's gonna help you.
I think that
nohup
it's gonna help you.
Thank you for this idea. I'll check it on my case.
I think that
nohup
it's gonna help you.
I've checked.
Not working in my case.
App still can't go to the next step after Run()
method.
Looking for another solution.
If you have some more advices, I will be pleased to check them :)
Update.
What really helped me is running with redirect to dev/null:
test, err := client.Run("some_cmd > /dev/null 2>&1 &")