From c43f34083dd9e3cd24a22237af3fe0d63128cafc Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Thu, 27 Jul 2023 17:00:05 -0400 Subject: [PATCH] copyto; abort when there is no stdin (#379) --- sdk/examples/pastebin/cmd/copyto/main.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/sdk/examples/pastebin/cmd/copyto/main.go b/sdk/examples/pastebin/cmd/copyto/main.go index 3cf769da..5d3d0c0b 100644 --- a/sdk/examples/pastebin/cmd/copyto/main.go +++ b/sdk/examples/pastebin/cmd/copyto/main.go @@ -16,10 +16,15 @@ const MAX_PASTE_SIZE = 64 * 1024 var data []byte func main() { - var err error - data, err = io.ReadAll(os.Stdin) - if err != nil { - panic(err) + stat, _ := os.Stdin.Stat() + if stat.Mode()&os.ModeCharDevice == 0 { + var err error + data, err = io.ReadAll(os.Stdin) + if err != nil { + panic(err) + } + } else { + panic("usage: 'copyto' is requires input from stdin; pipe your paste buffer into it") } root, err := environment.LoadRoot()