Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support unix exec for replacing current process #61

Open
neilyio opened this issue Apr 12, 2024 · 0 comments
Open

Support unix exec for replacing current process #61

neilyio opened this issue Apr 12, 2024 · 0 comments

Comments

@neilyio
Copy link

neilyio commented Apr 12, 2024

It would be handy to be able to use Command::exec() with a convenient macro. I commonly use this when I need to transform the current process entirely into another process without creating a new subprocess. This can be particularly useful for creating wrappers around other programs or for use in certain types of daemon processes.

For example:

use std::os::unix::process::CommandExt;
use std::process::Command;

fn main() {
    let error = Command::new("ls")
        .arg("-l")
        .arg("/home")
        .exec();  // Replaces the current process with `ls`

    eprintln!("Failed to execute ls: {}", error);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant