Skip to content

Implement Execv function (equivalent to Exec but with args passed as … #189

New issue

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

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

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

paulc
Copy link

@paulc paulc commented Aug 25, 2023

Hello,

Really enjoying using script however there have been a couple of use cases where I have wanted to avoid interpolating the Exec args into a single cmdLIne (and worrying about quoting - which can be complex if dealing with arbitrary input) and have therefore added an Execv(cmd string, args []string) method which passes the cmd and args separately as []string (which is what gets passed to exec.Command anyway so saves re-parsing the command line).

Think this would be a useful addition (and be safer for scripts which make need to Exec commands where some of the parameters are untrusted)

…[]string vs inetrpolated into single cmdLine)
@paulc paulc mentioned this pull request Aug 25, 2023
Comment on lines +425 to +426
err := cmd.Start()
if err != nil {

Choose a reason for hiding this comment

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

Suggested change
err := cmd.Start()
if err != nil {
if err := cmd.Start(); err != nil {

@jesselang
Copy link
Contributor

I would very much appreciate having this slice-based Exec! Is this PR being considered?

```go
args := []string{};
args = append(args,"127.0.0.1")
script.Exec("ping",args).Stdout()

Choose a reason for hiding this comment

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

Would that be Execv?

Suggested change
script.Exec("ping",args).Stdout()
script.Execv("ping", args).Stdout()

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants