【问题标题】:How to call a batch file from a Visual Studio Code extension command into the Integrated Terminal如何从 Visual Studio Code 扩展命令调用批处理文件到集成终端
【发布时间】:2018-04-04 15:22:33
【问题描述】:

我发布这个问题是因为我很难获得所需的行为:调用外部批处理文件 (.bat) 并在 VSCode 的集成终端中执行它。

需要注意的是,这个批处理文件调用的编译器可能需要几秒钟的时间来编译。

我的第一个方法是遵循 vscode 文档并编写一个任务来在终端中运行我的批处理脚本文件。但是,虽然任务确实调用了批处理文件,但它会随机崩溃并出现以下错误:

C:\UThe terminal process terminated with exit code: 1

随机我的意思是有时它会崩溃,有时它不会(对于相同的确切脚本)。我也开始注意到批处理文件调用的编译器编译的时间越长,崩溃的可能性就越大,这让我怀疑vscode集成终端不喜欢调用无响应的进程,所以它自己崩溃了?我不知道。

如果我从命令行或 powershell 调用这个批处理文件,它将 100% 运行,它只会在通过 vscode 任务调用时崩溃。

这导致我们采用第二种方法从 Visual Studio 代码中执行此批处理文件。我创建了一个扩展,它实现了一个通过 NODE.js 调用批处理文件的自定义 vscode 命令。

disposable = vscode.commands.registerCommand('extension.forceBuild', function (file) {
    console.log(rootPath);
    compiler.processControl(compiler.control_file,compiler.project_path);
    let execute_command = "start " + rootPath + "\\build.bat"  
    child_process.exec(execute_command, function(error, stdout, stderr) {
        console.log(stdout);
        if(error) console.log(error);
        if(stderr) console.log(stderr);
    });
}); 

这也有效,但是它将启动一个新的终端窗口,而不是使用 Visual Studio Code 的集成终端。我的问题是是否有任何方法可以使用此批处理文件或将其挂接到集成终端窗口。

【问题讨论】:

  • 嘿,您找到原始问题的解决方案了吗?

标签: node.js batch-file visual-studio-code vscode-extensions


【解决方案1】:

只要删掉“开始”命令

let execute_command = rootPath + "\\build.bat"  

【讨论】:

    猜你喜欢
    • 2017-05-13
    • 1970-01-01
    • 1970-01-01
    • 2022-10-14
    • 1970-01-01
    • 2017-07-25
    • 2015-11-11
    • 2018-03-09
    • 1970-01-01
    相关资源
    最近更新 更多