2011-11-28 99 views
0

我只是想獲得一些輸入和得到它後,我想以顯示它的ATM我這樣做是這樣的:它張貼兩次輸入

in := bufio.NewReader(os.Stdin); 
input, err = in.ReadString('\n'); 
if err != nil { 
    fmt.Println("Error: ", err) 
    os.Exit(1) 
} 
fmt.Printf("This is your", input) 

...但運行這個並輸入一些輸入後它始終如此顯示我的輸入兩次:

This is just a test 
This is your This is just a test 

是否有反正刪除第一行?

+0

這是您的真實密碼?您還沒有告訴'fmt.Printf'打印任何東西,除了最後沒有換行的靜態字符串。 – mkb

回答

1

我假設你的第一行只是你的回顯輸入文本?這實際上是流程終端的功能。由於go運行時像其他文件一樣對待Stdin,因此您無法直接訪問終端屬性。但是,您可能能夠與CGO一起攻擊某些東西,並使用描述here的方法。

4

我還沒有試過任何包裝,但我想這可能會有所幫助:exp/terminal。具體而言,ReadPasword功能文檔是:

ReadPassword reads a line of input from a terminal without local echo. 
This is commonly used for inputting passwords and other sensitive data. 
The slice returned does not include the \n.