Skip to content
This repository has been archived by the owner on Mar 23, 2021. It is now read-only.

Commit

Permalink
main: attach os.Stdin to command with -run (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
myitcv committed Feb 27, 2019
1 parent 392b803 commit 331f452
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ func mainerr() error {
case *fRun:
run := exec.Command(target, runArgs...)
run.Args[0] = path.Base(mp.ImportPath)
run.Stdin = os.Stdin
run.Stdout = os.Stdout
run.Stderr = os.Stderr
if err := run.Run(); err != nil {
Expand Down
15 changes: 13 additions & 2 deletions testdata/run.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Various -run tests

# Ensure os.Args[0] is set correctly
# Ensure os.Args[0] is set correctly and that Stdin is correctly
# attached
stdin input
gobin -m -run example.com/blah
stdout '^blah$'
cmp stdout output.golden

-- go.mod --
module example.com/blah
Expand All @@ -12,9 +14,18 @@ package main

import (
"fmt"
"io"
"os"
)

func main() {
fmt.Println(os.Args[0])
if _, err := io.Copy(os.Stdout, os.Stdin); err != nil {
panic(err)
}
}
-- input --
This is stdin
-- output.golden --
blah
This is stdin

0 comments on commit 331f452

Please sign in to comment.