Skip to content

implement exec for unix platforms - #2495

Merged
thegedge merged 6 commits into
nushell:mainfrom
almindor:issue_1799
Sep 5, 2020
Merged

thegedge merged 6 commits into
nushell:mainfrom
almindor:issue_1799

Conversation

@almindor

@almindor almindor commented Sep 4, 2020 •

Copy link
Copy Markdown
Contributor

Fix for #1799 by implementing a exec built-in using the std::os::unix::process::CommandExt trait.

NOTE: one thing I couldn't figure out how to do is for the exec args to allow -param passing, e.g. exec /some/cmd do_something works but exec /some/cmd --param won't because the parser thinks --param is for exec.

Comment thread crates/nu-cli/src/cli.rs Resolved
@fdncred

fdncred commented Sep 4, 2020

Copy link
Copy Markdown
Contributor

@almindor Is this a Linux/Mac only command, or does it work in Windows too?

@almindor

almindor commented Sep 4, 2020

Copy link
Copy Markdown
Contributor Author

@almindor Is this a Linux/Mac only command, or does it work in Windows too?

This is unix only, it's part of the POSIX spec. Windows has no concept of exec I think (e.g. replace process in place) but I'm not too familiar with Windows.

@thegedge thegedge left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few small things, but other than that, should be good to go!

I also wanted to note that I see POSIX mentioned (both here and the issue this PR fixes). I want to call out the nushell philosophy from our contributor book, specifically POSIX compliance is a non goal. Just wanted to make sure that was clear 🙂

Comment thread crates/nu-cli/src/commands/exec.rs Resolved
Comment thread crates/nu-cli/Cargo.toml Resolved
Comment thread crates/nu-cli/src/cli.rs Resolved
@almindor

almindor commented Sep 4, 2020

Copy link
Copy Markdown
Contributor Author

Just a few small things, but other than that, should be good to go!

I also wanted to note that I see POSIX mentioned (both here and the issue this PR fixes). I want to call out the nushell philosophy from our contributor book, specifically POSIX compliance is a non goal. Just wanted to make sure that was clear

Compliance is a non-goal and I never said that nu should be POSIX compliant. The reason why I listed is to show that exec isn't just expected to be a program executed instead of a built-in and that GDB is using it correctly.

Nu ensures direct compatibility with existing platform-specific executables that make up people’s workflows. is a goal tho and not having exec is in direct opposition to it.

@almindor

almindor commented Sep 5, 2020

Copy link
Copy Markdown
Contributor Author

This should be good to go now.

@thegedge thegedge left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basic functionality works on macOS and Windows 🙌

We may need to expand for env vars, but let's start here and expand.

@fdncred

fdncred commented Sep 5, 2020

Copy link
Copy Markdown
Contributor

On MacOs, I run the example exec ps aux and it does the ps command and then exits nushell. Is that what it's supposed to do?

@thegedge

thegedge commented Sep 5, 2020

Copy link
Copy Markdown
Contributor

Is that what it's supposed to do?

Yep. Remember, exec replaces the process, so nushell "disappears" and gets replaced with ps. ps then completes and you're back to whatever originally spawned nushell.

@almindor

almindor commented Sep 5, 2020

Copy link
Copy Markdown
Contributor Author

On MacOs, I run the example exec ps aux and it does the ps command and then exits nushell. Is that what it's supposed to do?

Indeed, @thegedge explained it well. Maybe I could add more info in the help description to make it clear exec replaces the shell.

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

Successfully merging this pull request may close these issues.

3 participants