首先,我知道有很多方法可以捕获shell的输出...我找到this并且工作正常:
from subprocess import Popen, PIPE
with Popen(["ping", "localhost"], stdout=PIPE, bufsize=1, universal_newlines=True) as p:
for line in p.stdout:
if "bytes" in line:
print(line, end='')
但我需要从de cmd获取调试信息,这不起作用...... 我试图从geth得到一些信息,如:
mypc@thispc:~$ geth --light
INFO [07-02|21:56:08] Starting peer-to-peer node
INFO [07-02|21:56:08] Allocated cache and file handles
INFO [07-02|21:56:08] Initialised chain configuration
INFO [07-02|21:56:08] Disk storage enabled for ethash caches
INFO [07-02|21:56:08] Disk storage enabled for ethash DAGs
INFO [07-02|21:56:08] Added trusted CHT for mainnet
INFO [07-02|21:56:08] Loaded most recent local header
这是调试信息所以,我不知道为什么,但我无法正常捕获它。我需要这样的东西:
with Popen(["geth", "--light"], stdout=PIPE, bufsize=1, universal_newlines=True) as p:
for line in p.stdout:
if "Loaded" in line:
print("NICE!!")
有什么办法吗?
答案 0 :(得分:0)
感谢 kwarunek 的答案,它有效
调试消息经常在stderr中。尝试捕获stderr stderr = PIPE然后是p.stderr
private void updateToggleButtonStates(ToggleButton[][] buttons, int x, int y) {
for (int i = 0 ; i < buttons.length ; i++) {
for (int j = 0 ; j < buttons[i].length ; j++) {
buttons[i][j].setDisable(Math.abs(i-x) > 1 || Math.abs(j-y) > 1);
}
}
}