美文网首页
go stdin stdout stderr

go stdin stdout stderr

作者: wyrover | 来源:发表于2018-06-22 21:49 被阅读42次

    stdERR.go

    package main
    
    import (
        "io"
        "os"
    )
    
    func main() {
        myString := ""
        arguments := os.Args
        if len(arguments) == 1 {
            myString = "Please give me one argument!"
        } else {
            myString = arguments[1]
        }
    
        io.WriteString(os.Stdout, "This is Standard output\n")
        io.WriteString(os.Stderr, myString)
        io.WriteString(os.Stderr, "\n")
    }
    
    

    stdIN.go

    package main
    
    import (
        "bufio"
        "fmt"
        "os"
    )
    
    func main() {
        var f *os.File
        f = os.Stdin
        defer f.Close()
    
        scanner := bufio.NewScanner(f)
        for scanner.Scan() {
            fmt.Println(">", scanner.Text())
        }
    }
    
    

    stdOUT.go

    package main
    
    import (
        "io"
        "os"
    )
    
    func main() {
        myString := ""
        arguments := os.Args
        if len(arguments) == 1 {
            myString = "Please give me one argument!"
        } else {
            myString = arguments[1]
        }
    
        io.WriteString(os.Stdout, myString)
        io.WriteString(os.Stdout, "\n")
    }
    
    

    相关文章

      网友评论

          本文标题:go stdin stdout stderr

          本文链接:https://www.haomeiwen.com/subject/gyulyftx.html