I have to promt for some input from os.stdin.How can I check this is available for reading before printing statements like "Enter your text" and then read from input.If stdin is not available it is printing bad file descriptor after "Enter your text". how to avoid this?
package main
import (
"bufio"
"os"
"io"
"fmt"
)
func main(){
consSource := NewConsoleAccessTokenSource("www.google.co.in", os.Stdin)
fmt.Print("Token: ")
consSource.scanner.Scan()
err := consSource.scanner.Err()
if err != nil {
fmt.Print(err)
}
fmt.Print(consSource.scanner.Text())
}
func NewConsoleAccessTokenSource(websiteUrl string, reader io.Reader) *ConsoleAccessTokenSource {
s := &ConsoleAccessTokenSource{}
s.WebsiteUrl = websiteUrl
s.scanner = bufio.NewScanner(reader)
return s
}
type ConsoleAccessTokenSource struct {
WebsiteUrl string
scanner *bufio.Scanner
}
This is what I am trying to do .when I run this program using "nohup executable" it is giving bad file descriptor.