我正在尝试检查运行命令的输出"ssh -T git@github.com"
输出应如下所示:
嗨,xyz!你已成功进行身份验证,但 GitHub 不提供 shell 访问权限。
但是,我无法捕获此输出。此文本来自何处,如何访问它以便对其进行测试?
管道输出或写入文件不会产生任何结果。
ssh -T git@github.com | grep "successful"
这里的 Grep 没有收到任何输入。
错误消息通常写入名为 Stderr 的单独"流"。
您可以重定向要与 StdOut(输出(合并的 StdErr 输出。
git@github.com 2>&1 | grep "successful"
将解决您的问题。
2>&1
|| |
|| +-> 1 is the filehandle num assosciated with stdin
|+---> >& redirects from left to right, "merging" the 2 specified streams
+===-> 2 is the filehandle number for stderr