VSCode有一个Windows API,可以与终端进行交互。
例如,您可以发送Linux命令
这似乎有效,但我想知道是否有更优雅的方法。
我确定上面的代码可以工作,因为我可以使用以下方法将输出写入文件:
问题是,如何将
例如,您可以发送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()
的输出作为字符串获取,而不必先写入磁盘?