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

os/exec: Command() SPLAT help #20893

Closed
davidrenne opened this issue Jul 3, 2017 · 3 comments
Closed

os/exec: Command() SPLAT help #20893

davidrenne opened this issue Jul 3, 2017 · 3 comments

Comments

@davidrenne
Copy link

What version of Go are you using (go version)?

1.8

What operating system and processor architecture are you using (go env)?

amd64

What did you do?

I cant seem to exec.Command() on any parameter which has a * or splat character. They all fail.

What did you expect to see?

I expect it to run like it runs in the shell.

What did you see instead?

err returned.

Please help!! My workaround is to write my shell script to disk and exec it and it works perfectly fine.

@zegl
Copy link
Contributor

zegl commented Jul 3, 2017

Shell expansion (such as *) is a feature of the shells, not of the program that is executed, or of Go.

You need to provide all parameters yourself. If you want to send a list of files to the command, you can use io/ioutil.ReadDir to build the list manually.

@bradfitz
Copy link
Contributor

bradfitz commented Jul 3, 2017

What @zegl said. os/exec intentionally does not provide shell expansion APIs. You need to either explicitly exec the shell and have the shell do it, or explicitly glob yourself and pass the files.

For questions about Go, see https://golang.org/wiki/Questions.

@bradfitz
Copy link
Contributor

bradfitz commented Jul 3, 2017

I realize though that this isn't explicitly documented, so I opened #20894.

@mikioh mikioh changed the title exec.Command() SPLAT help os/exec: Command() SPLAT help Jul 10, 2017
@golang golang locked and limited conversation to collaborators Jul 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants