Skip to content

os/exec: does not report error for exec.Command when the file does not exist #23437

@dongweigogo

Description

@dongweigogo

go 1.8.4

In running an exec.Command against files, Go does not report any error when the file does not exist. A simple example as below:

``

    cmd:=exec.Command("grep", "abc", "test.txt")     //actually, "test.txt" does not exist
    so,err1:=cmd.StdoutPipe()
    fmt.Println(err1)
    cmd.Start()
    buf,err2:=ioutil.ReadAll(so)
    fmt.Println(string(buf), err2)
    cmd.Wait()

``
Both err1 and err2 are nil, and no error is shown. It looks like the program runs successfully, but actually not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions