madelson / MedallionShell

A .NET library simplifying the execution and chaining of processes
MIT License
415 stars 32 forks source link

Using nohup to run commands in the background #106

Open jrt324 opened 10 months ago

jrt324 commented 10 months ago

I need to execute a background program in Linux through MedallionShell, and even if the host's .net process is exited, the executed command will not be terminated. So far, this is what I have thought of is for Example: nohup roslaunch test_launch agv.launch & Please note that I added an '&' symbol at the end that means this command will run on background. but this is not working , If i remove the end of '&', Then it can execute but this command Thread never end (Because it's long running processes)

I don't know the reason, or if there are any other solutions, please let me know.

The two goals I want to achieve are:

  1. Running the command line in the background, and
  2. Even if the .net Main process exits, the executed command line will not terminate.
madelson commented 10 months ago

@jrt324 keep in mind that MedallionShell runs processes; it isn’t a shell environment like bash. So there’s no “&” syntax because that’s shell syntax.

For a long-running process, the MedallionShell command will never finish. Therefore, you probably want to turn off stdio redirection which can be done via the start info command option. Otherwise, the host process will be capturing the downstream process’s output.

Another option for something like this is to use MedallionShell to run bash (or any shell). Then you can execute commands with bash syntax and capabilities, eg;

Command.Run(“bash”, “-c”, [“nohup … &”]);

If you can’t get it working, please post the specific code you’re trying to run