运行 自定义原子包中的终端命令

run terminal commands in custom atom package

我目前正在创建一个 atom 包,其中 运行s 命令在 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);
}

我不知道如何生成命令 window 或如何 运行 命令。所有这些代码所做的就是检查用户是否在文本 window 中,然后出于测试目的将路径插入到文本 window 中。最终,我将需要 运行 cd path.

要执行程序,可以使用 with child_process module that's bundled with Node (Atom has its own wrapper for it, see 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});

出于调试目的,您可能想使用 console-panel 之类的东西来打印消息。