child_process无法在扩展名中使用(vscode)

时间:2020-09-25 07:22:27

标签: node.js visual-studio-code

我有一个正常.ts格式的程序

var spawn = require('child_process').spawn;
var child = spawn("dir",{shell:true});
child.stdout.on("data",function(data){
console.log('data\n ' + data);});

,最终结果是 enter image description here

但是当我使用vscode扩展模块时。

function activate(context) {
console.log('Congratulations, your extension "helloworld-minimal-sample" is now active!');
var spawn = require('child_process').spawnSync;

var child = spawn("dir",{shell:true});

child.stdout.on("data",function(data){
    console.log('data\n ' + data);
});

console.log('stdout here: \n' + child.stdout);

let disposable = vscode.commands.registerCommand('extension.helloWorld', () => {

    vscode.window.showInformationMessage('Hello World!');
});

context.subscriptions.push(disposable);
}

Same api but the shell does not show directory

但这不显示目录。 如何解决?

0 个答案:

没有答案