javascript - 在自定义 atom 包中运行终端命令
问题描述
我目前正在创建一个 atom 包,它在 windows 命令提示符而不是atom 命令提示符上运行命令。到目前为止,我只有代码:
if (editor = atom.workspace.getActiveTextEditor()){
let editor = atom.workspace.getActiveTextEditor();
let file = editor.buffer.file;
let path = file.path;
editor.save();
editor.insertText(path);
}
我不知道如何生成命令窗口或如何运行命令。该代码所做的只是检查用户是否在文本窗口中,然后出于测试目的将路径插入文本窗口。最终,我将需要运行cd path
.
解决方案
要执行程序,您可以使用child_process
与 Node 捆绑在一起的 with 模块(Atom 有自己的包装器,请参阅BufferedProcess
)
例子:
// Somewhere in your header
const { spawn } = require('child_process');
// Where you need to execute the Java compiler
const javac = spawn('javac', [path], {stdio: inherit});
出于调试目的,您可能希望使用控制台面板之类的东西来打印消息。
推荐阅读
- docker - 具有外部包依赖的Golang测试没有通过Gitlab Ci,而是通过本地
- c++ - 在 xcode 中使用 djinni 时“使用未声明的标识符”“noreturn”
- winapi - 如何只安装 mt.exe?
- rest - 使用 REST 返回一个值
- reactjs - nextjs中“页面”内的CSS
- c++ - 如何在类中分配多维数组?当行>列时会引发错误?
- javascript - Node js 使用 mocha chai 测试受保护的路由?
- wso2 - 是否可以使用 wso2 Identity Server 获取非 oauth2 令牌并将其与 wso2 APIManager 一起使用?
- php - 如何获取指定了所有关系数据的数据
- spring-boot - 在 docker-compose 上为 Spring Boot 应用程序发送应用程序参数?