【发布时间】:2019-07-19 11:43:02
【问题描述】:
VSCode 有一个Windows API,允许与终端交互。
比如你可以发送Linux命令pwd&命令输出可能是/usr/home/userName
我尝试将输出写入磁盘,然后稍后使用pwd > directory.txt 之类的方式读取它;
terminal.sendText(`pwd > directory.txt`);
这似乎可行,但我想知道是否有更优雅的东西。
//Create a new terminal
let terminal = vscode.window.createTerminal(`Name of terminal`, 'C:\path\to\terminal\shell\shell.exe');
// send command to newly created terminal
terminal.sendText(`pwd`);
我确信上面的代码可以工作,因为我可以使用;
将输出写入文件terminal.sendText(`pwd > directory.txt`);
所以问题是,我如何将terminal.sendText() 的输出作为字符串获取,而不必先将它们写入磁盘?
【问题讨论】:
-
如果您不需要在 UI 终端中显示正在运行的命令,您可以使用 Node 的 exec / spawn API:stackoverflow.com/questions/20643470/…
-
我已经用 node-cmd 包尝试过这个,它似乎不适用于 Linux 的 Windows 子系统
标签: typescript visual-studio-code vscode-extensions