相关疑难解决方法(0)

如何从shell脚本获取密码而不进行回显

我有一个脚本可以自动执行需要访问受密码保护的系统的进程.通过命令行程序访问系统,该程序接受用户密码作为参数.

我想提示用户键入他们的密码,将其分配给shell变量,然后使用该变量构建访问程序的命令行(这当然会产生我将处理的流输出).

我是Bourne/Bash中一个相当称职的shell程序员,但我不知道如何接受用户输入而不让它回显到终端(或者可能使用'*'字符回显).

有人能帮忙吗?

bash shell scripting sh

384
推荐指数
8
解决办法
32万
查看次数

为什么它没有endl包裹;?

我是一名C++初学者,我刚刚编写了这个简单的程序:

#include <iostream>

using namespace std;

int readNumber()
{
    cout << "Insert a number: ";
    int x;
    cin >> x;
    return x;
}

void writeAnswer(int x)
{
    cout << "The sum is: " << x << endl;
}

int main()
{
    int x = readNumber();
    int y = readNumber();
    int z = x + y;
    writeAnswer(z);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我不明白为什么输出是这样的:

Insert a number: 3
Insert a number: 4
The sum is: 7
Run Code Online (Sandbox Code Playgroud)

而不是像:

Insert a number: 3Insert a number: 4The …
Run Code Online (Sandbox Code Playgroud)

c++

10
推荐指数
1
解决办法
163
查看次数

为什么.NET Core在Raspbian上处理ReadKey的方式不同?

我正在编写.NET Core控制台应用程序.我想将控制台输入限制为每个输入的特定数量的最大字符.我有一些代码通过构建一个字符串Console.ReadKey()而不是Console.ReadLine()Everything在Windows上完美地测试它来实现这一点.然后,当我部署到运行Raspbian的Raspberry Pi 3时,我很快遇到了各种各样的问题.我记得Linux处理行结尾的方式与Windows不同,似乎退格处理方式也不同.我改变了处理它们的方式,取消了ConsoleKey而不是字符,换行问题消失了,但退格只是有时会注册.此外,有时字符会输出到我输入框外的控制台,即使我将ReadKey设置为不自行输出到控制台.我错过了Linux处理控制台输入的方法吗?

//I replaced my calls to Console.ReadLine() with this. The limit is the
//max number of characters that can be entered in the console.
public static string ReadChars(int limit)
{
    string str = string.Empty; //all the input so far
    int left = Console.CursorLeft; //store cursor position for re-outputting
    int top = Console.CursorTop;
    while (true) //keep checking for key events
    {
        if (Console.KeyAvailable)
        {
            //true to intercept input and not output to console
            //normally. …
Run Code Online (Sandbox Code Playgroud)

c# console-application raspberry-pi .net-core

9
推荐指数
1
解决办法
774
查看次数

标签 统计

.net-core ×1

bash ×1

c# ×1

c++ ×1

console-application ×1

raspberry-pi ×1

scripting ×1

sh ×1

shell ×1