doudi8829 2014-01-03 06:27
浏览 151
已采纳

如何使用读取系统调用以交互方式获取密码

how do I implement the following command line using system calls in golang?

read -s -p "Enter Password: " mypassword

that is, what additional options to set while reading the password to avoid the input to be echoed and force the input to be provided only interactively.

thanks.

  • 写回答

2条回答 默认 最新

  • dongre8505 2014-01-03 13:50
    关注

    You can use terminal.ReadPassword() from package terminal.

    func ReadPassword(fd int) ([]byte, error)
    

    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 .

    Package terminal provides support functions for dealing with terminals, as commonly found on UNIX systems.

    More on it:

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?