Skip to content

os/exec: Cmd does not attempt to run ./prog.exe, when execution of ./prog requested #7377

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

Closed
alexbrainman opened this issue Feb 21, 2014 · 2 comments
Milestone

Comments

@alexbrainman
Copy link
Member

Apply this diff:

diff --git a/src/pkg/os/exec/exec_test.go b/src/pkg/os/exec/exec_test.go
--- a/src/pkg/os/exec/exec_test.go
+++ b/src/pkg/os/exec/exec_test.go
@@ -687,3 +687,23 @@
        os.Exit(2)
    }
 }
+
+func TestWindowsRelativeCommandWithoutExtention(t *testing.T) {
+   cd, err := os.Getwd()
+   if err != nil {
+       t.Fatalf("Getwd: %v", err)
+   }
+   defer os.Chdir(cd)
+
+   bindir := filepath.Join(runtime.GOROOT(), "bin")
+   err = os.Chdir(bindir)
+   if err != nil {
+       t.Fatalf("Chdir(%v): %v", bindir, err)
+   }
+   // the file name is actually go.exe on windows
+   cmd := exec.Command("./go", "env")
+   out, err := cmd.CombinedOutput()
+   if err != nil {
+       t.Errorf("cmd failed: %v %v", err, string(out))
+   }
+}

to hg id b5eda189b974

and run the test. It should succeed, but fails on windows with:

C:\go\root\src>u:\test -test.v -test.run=Exten
=== RUN TestWindowsRelativeCommandWithoutExtention
--- FAIL: TestWindowsRelativeCommandWithoutExtention (0.00 seconds)
        exec_test.go:707: cmd failed: fork/exec ./go: The system cannot find the file specified.
FAIL

The problem is introduced by:

os/exec: fix Command with relative paths

Command was (and is) documented like:
"If name contains no path separators, Command uses LookPath to
resolve the path to a complete name if possible. Otherwise it
uses name directly."

But that wasn't true. It always did LookPath, and then
set a sticky error that the user couldn't unset.
And then if cmd.Dir was changed, Start would still fail
due to the earlier sticky error being set.

This keeps LookPath in the same place as before (so no user
visible changes in cmd.Path after Command), but only does
it when the documentation says it will happen.

Also, clarify the docs about a relative Dir path.

No change in any existing behavior, except using Command
is now possible with relative paths. Previously it only
worked if you built the *Cmd by hand.

Fixes  issue #7228 

LGTM=iant
R=iant
CC=adg, golang-codereviews
https://golang.org/cl/59580044

The problem was first discovered when 48a4a9afb88b failed on windows. I also think that
our current windows-386 builder is broken for the same reason. It outputs:

fork/exec c:\gobuilder\windows-386-ec2-b5eda189b974\go\bin\go: The system cannot find
the file specified.

for every subrepo build.

Alex
@alexbrainman
Copy link
Member Author

Comment 1:

https://golang.org/cl/83020043/

Status changed to Started.

@bradfitz
Copy link
Contributor

Comment 2:

*** Submitted as https://code.google.com/p/go/source/detail?r=0bf0c11aea78 ***

Status changed to Fixed.

@rsc rsc added this to the Go1.3 milestone Apr 14, 2015
@rsc rsc removed the release-go1.3 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
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