How to run a system command from VSCode extension

三世轮回 提交于 2020-05-25 03:34:12

问题


I am trying to create a simple VSCode extension to run a set of commands when I open a folder. Basically these commands will set up our development environment. I have started off creating the boilerplace and ran through the example that VSCode provided but I am not clear how to run system commands. Appreciate any help or point me to some documentation about this topic.


回答1:


Your extension environment has access to node.js libraries, so you can just use child_process or any helper libraries to execute commands:

const cp = require('child_process')
cp.exec('pwd', (err, stdout, stderr) => {
    console.log('stdout: ' + stdout);
    console.log('stderr: ' + stderr);
    if (err) {
        console.log('error: ' + err);
    }
});


来源:https://stackoverflow.com/questions/43007267/how-to-run-a-system-command-from-vscode-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!