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

Migrate from Process (using bash -c) to posix_spawn #10

Open
Samasaur1 opened this issue Oct 15, 2022 · 0 comments · May be fixed by #17
Open

Migrate from Process (using bash -c) to posix_spawn #10

Samasaur1 opened this issue Oct 15, 2022 · 0 comments · May be fixed by #17

Comments

@Samasaur1
Copy link
Owner

I know the title makes it seem like we're going backwards in time, not forwards, but in my experience something like the following works better:

var pid: pid_t = 0
let args = ["/usr/bin/env"] + effectiveEditor + [dir + "/" + helpme + ".txt"]
let c_args = args.map { $0.withCString(strdup)! }
posix_spawn(&pid, c_args[0], nil, nil, c_args + [nil], environ)
waitpid(pid, nil, 0)

(from helpme-swiftly)

This should also work better with lots of arguments, especially quoted ones, since we're invoking the actual command rather than /bin/bash -c "command and arguments"

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 a pull request may close this issue.

1 participant