如何从 VSCode 扩展运行系统命令 [英] How to run a system command from VSCode extension

查看:56
本文介绍了如何从 VSCode 扩展运行系统命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个简单的 VSCode 扩展,以便在打开文件夹时运行一组命令.基本上这些命令将设置我们的开发环境.我已经开始创建样板并运行了 VSCode 提供的示例,但我不清楚如何运行系统命令.感谢任何帮助或向我指出有关此主题的一些文档.

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.

推荐答案

您的扩展环境可以访问 node.js 库,因此您只需使用 child_process 或任何帮助库来执行命令:

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);
    }
});

这篇关于如何从 VSCode 扩展运行系统命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆