如何使用终端API侦听vscode中的所有终端输出? [英] How to use Terminal API to listen to all terminal output in vscode?
本文介绍了如何使用终端API侦听vscode中的所有终端输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想听扩展程序的终端输出,例如 tsc -w
,并在输出包含相似文本的情况下抓紧时间:
I want to listen to terminal output from extension, such as tsc -w
and catch the moment if the output contains similar text:
发现1错误。
Found 1 error. Watching for file changes.
或者错误退出代码或类似的东西。
Or the error exit code or something like that. Is it possible to do with old API or Proposed API?
尝试过:
terminal.onDidWriteData(data => {
console.log('onDidWriteData: ', data.trim());
});
它只是输出自动生成的垃圾,例如:
It just outputs autogenerated rubbish like:
Windows PowerShell
版权所有(C)Microsoft Corporation。保留所有权利。
Windows PowerShell Copyright (C) Microsoft Corporation. All rights reserved.
推荐答案
好像在内部专家版中已弃用。尝试使用 window.onDidWriteTerminalData
:
Looks like it is deprecated in insiders edition. Try using window.onDidWriteTerminalData
:
window.onDidWriteTerminalData(event => console.log(event.data.trim()))
参考
- https://github.com/microsoft/vscode/issues/78574
- https://github.com/microsoft/vscode/issues/78574
Reference
这篇关于如何使用终端API侦听vscode中的所有终端输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文