运行实用程序时如何将控制台输出捕获到变量中,以便过滤文本?
示例:我试图在键入时捕获控制台输出,bitcoind
以便可以过滤掉rpcpassword并将其写入配置文件。
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" admin@foo.com
Run Code Online (Sandbox Code Playgroud)
将输出重定向到一个文件,例如
bitcoind >~/bitcoind_output.txt 2>&1
Run Code Online (Sandbox Code Playgroud)
这会将输出放在您的主目录中名为 bitcoind_output.txt 的文件中