将控制台输出捕获到变量中吗?

将控制台输出捕获到变量中吗?

在运行实用程序时,如何将控制台输出捕获到变量中,以便我可以过滤文本?


例子:我试图在输入时捕获控制台输出,bitcoind 以便可以过滤掉rpc密码并将其写入配置文件。

ubuntu@ip-172-31-3-49:~$ bitcoind
Error: To use bitcoind, you must set a rpcpassword in the configuration file:
/home/ubuntu/.bitcoin/bitcoin.conf
It is recommended you use the following random password:
rpcuser=bitcoinrpc
rpcpassword=Eb5WDgzKqt77U4LhvvfnYxaNvw2rpztSvM5XKsonXBWC
(you do not need to remember this password)
The username and password MUST NOT be the same.
If the file does not exist, create it with owner-readable-only file permissions.
It is also recommended to set alertnotify so you are notified of problems;
for example: alertnotify=echo %s | mail -s "Bitcoin Alert" [email protected]

答案1

将输出重定向到文件,例如

bitcoind >~/bitcoind_output.txt 2>&1

这会将输出放入主目录中名为 bitcoind_output.txt 的文件中

答案2

要将输出捕获到变量中:

output=$(bitcoind 2>&1)

相关内容