在人们开始哭喊“复制”之前,我已经检查过了
其中的第一个问题在不同的用例中基本上是相同的问题,因此答案不涉及我的用例。
所以..。如何对命令行进行编码,如下面这样的命令行,将命名的参数与它们的值用空格分隔开来?
arduino-cli compile --fqbn arduino:avr:nano应该是这样(1)吗?
let cp = child.process(
"/path/to/arduino-cli.exe",
[
"compile",
"--fqbn arduino:avr:nano"
]
);还是这个(2)?
let cp = child.process(
"/path/to/arduino-cli.exe",
[
"compile",
"--fqbn",
"arduino:avr:nano"
]
);还是这个(3)?
let cp = child.process(
"/path/to/arduino-cli.exe",
[
"compile",
"fqbn",
"arduino:avr:nano"
]
);还是这个(4)?
let cp = child.process(
"/path/to/arduino-cli.exe",
{
_: ["compile"],
fqbn: "arduino:avr:nano"
}
);TypeScript不允许最后一种选择,尽管我怀疑这是正确的答案,所以我将这个问题提交给更广泛的考虑。
发布于 2020-10-08 01:32:12
在设置可重复测试之后
let args: any[] = [];
args.push(["compile", `--fqbn ${selectedBoard.board.fqbn}`]);
args.push(["compile", "--fqbn", selectedBoard.board.fqbn]);
args.push(["compile", "fqbn", selectedBoard.board.fqbn]);
args.push({ _: ["compile"], fqbn: selectedBoard.board.fqbn });
let cp = child_process.spawn(cliPath, args[1], { cwd: getInoPath() });
cp.stdout.on("data", (data: any) => outputChannel.append(data.toString()));
cp.stderr.on("data", (data: any) => outputChannel.append(data.toString()));
cp.on("error", (err: any) => {
outputChannel.append(err);
});我发现@jfriend00是对的,它确实是第二个参数版本。
["compile", "--fqbn", selectedBoard.board.fqbn]但是还有另一个导致它失败的问题-- CWD需要在选项中设置。
let cp = child_process.spawn(cliPath, args[1], { cwd: getInoPath() });这里的关键洞察力是捕获错误事件和stderr。在stderr上报告了故障,没有引发错误事件。在公开stderr之后,问题很快就解决了。
https://stackoverflow.com/questions/64254174
复制相似问题