Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 如何将批处理文件从Visual Studio代码扩展名命令调用到集成终端_Node.js_Batch File_Visual Studio Code_Vscode Extensions - Fatal编程技术网

Node.js 如何将批处理文件从Visual Studio代码扩展名命令调用到集成终端

Node.js 如何将批处理文件从Visual Studio代码扩展名命令调用到集成终端,node.js,batch-file,visual-studio-code,vscode-extensions,Node.js,Batch File,Visual Studio Code,Vscode Extensions,我之所以提出这个问题,是因为我很难获得想要的行为:调用外部批处理文件(.bat)并在VSCode中的集成终端中执行它 需要注意的是,这个批处理文件调用的编译器可能需要几秒钟的时间来编译 我的第一步是遵循vscode文档,编写一个任务,在终端中运行批处理脚本文件。但是,虽然任务确实调用了批处理文件,但它会随机崩溃,并出现以下错误: C:\UThe terminal process terminated with exit code: 1 我所说的随机性是指它有时会崩溃,有时不会(对于相同的脚本)

我之所以提出这个问题,是因为我很难获得想要的行为:调用外部批处理文件(.bat)并在VSCode中的集成终端中执行它

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

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

C:\UThe terminal process terminated with exit code: 1
我所说的随机性是指它有时会崩溃,有时不会(对于相同的脚本)。我还开始注意到,批处理文件调用的编译器编译的时间越长,崩溃的可能性就越大,这让我怀疑vscode集成终端不喜欢调用无响应的进程,所以它会自己崩溃?我不知道

如果我从命令行或powershell调用此批处理文件,它将在100%的时间内运行,那么它只有在通过vscode任务调用时才会崩溃,这一点也毫无意义

这将引导我们进入第二个步骤,从VisualStudio代码执行此批处理文件。我创建了一个扩展,该扩展实现了一个自定义vscode命令,该命令通过NODE.js调用批处理文件

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);
    });
}); 
这也是可行的,但是它将启动一个新的终端窗口,而不是使用VisualStudio代码的集成终端。我的问题是,是否需要使用此批处理文件或将其挂接到集成终端窗口。

只需删除“start”命令即可


嘿,你找到解决你原来问题的办法了吗?
let execute_command = rootPath + "\\build.bat"