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

Commit 331f452

Browse files
authored
main: attach os.Stdin to command with -run (#66)
1 parent 392b803 commit 331f452

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ func mainerr() error {
347347
case *fRun:
348348
run := exec.Command(target, runArgs...)
349349
run.Args[0] = path.Base(mp.ImportPath)
350+
run.Stdin = os.Stdin
350351
run.Stdout = os.Stdout
351352
run.Stderr = os.Stderr
352353
if err := run.Run(); err != nil {

testdata/run.txt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# Various -run tests
22

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

79
-- go.mod --
810
module example.com/blah
@@ -12,9 +14,18 @@ package main
1214

1315
import (
1416
"fmt"
17+
"io"
1518
"os"
1619
)
1720

1821
func main() {
1922
fmt.Println(os.Args[0])
23+
if _, err := io.Copy(os.Stdout, os.Stdin); err != nil {
24+
panic(err)
25+
}
2026
}
27+
-- input --
28+
This is stdin
29+
-- output.golden --
30+
blah
31+
This is stdin

0 commit comments

Comments
 (0)