Skip to content

os, os/exec: using redirection symbol '<' '>' failed #11866

@liugangnhm

Description

@liugangnhm

when an using exec.Cmd to fock an subprocess,with redirection like cat xxx > /tmp/xxxx ,it will always fail.

cmd:=exec.Command("cat","./aaa",">","/tmp/aaa")
cmd.Start()
err:=cmd.Wait()
if err!=nil {
    t.Errorf("exit error %s", err)
}

wheather /tmp/aaa is exist or not, error is always "exit status 1" .
file aaa is always exist.

when i set cmd's Stderr to bytes.Buffer ,and i see detail error:"cat: >d: no such file or directory". so i think go maybe treat '>' as a file name.

so how should i do when i want to use redirection symbol in command

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions