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

cmd/go: run with "--" leaks "--" into os.Args #10241

Closed
josharian opened this issue Mar 25, 2015 · 2 comments
Closed

cmd/go: run with "--" leaks "--" into os.Args #10241

josharian opened this issue Mar 25, 2015 · 2 comments

Comments

@josharian
Copy link
Contributor

When -- is used to separate arguments from input files to go run, the -- is passed to the executed program as os.Args[1]. It should not be. To reproduce:

x.go:

package main

import (
    "fmt"
    "os"
)

func main() {
    fmt.Println(os.Args)
}

x2.go:

package main

Execute:

$ go run x.go x2.go -- abc

Result:

[/var/folders/jw/xrvq7wz95p5bwvjyx9yc2npm390cfb/T/go-build390645411/command-line-arguments/_obj/exe/gr -- abc]

Want:

[/var/folders/jw/xrvq7wz95p5bwvjyx9yc2npm390cfb/T/go-build390645411/command-line-arguments/_obj/exe/gr abc]
@bradfitz
Copy link
Contributor

I don't think -- is an explicitly supported feature. In fact, I think it was explicitly rejected in the past. What you're seeing is a side effect: once files no longer match *.go, they're arguments.

Yes, cmd/go/run.go's func runRun seems to confirm:

func runRun(cmd *Command, args []string) {                                                                  |Warning (server): Unable to start the Emacs server.
        raceInit()                                                                                          |There is an existing Emacs server, named "server".
        var b builder                                                                                       |To start the server in this Emacs process, stop the existing
        b.init()                                                                                            |server or call `M-x server-force-delete' to forcibly disconnect it.
        b.print = printStderr                                                                               |
        i := 0                                                                                              |
        for i < len(args) && strings.HasSuffix(args[i], ".go") {                                            |
                i++                                                                                         |
        }                                                                                                   |
        files, cmdArgs := args[:i], args[i:]                                                                |

@josharian
Copy link
Contributor Author

Blech. And adding it was explicitly rejected? Sigh, ok. Guess it is working as intended. (Yes, yes, I know, don't use go run.)

@golang golang locked and limited conversation to collaborators Jun 25, 2016
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

3 participants