我正在尝试使用目标设备启动 cordova 命令。我已经测试了该命令并且它有效,但是当我尝试用我的代码生成它时,它忽略等号,因此不会运行。此代码确实可以工作,只是不添加 "--target='iPhone-7-Plus"
return new Promise((resolve, reject) => {
const executable = "ionic";
const arguments = [
"cordova",
buildOnly ? "build" : "run",
platform,
"--no-interactive",
"--verbose",
"--target='iPhone-7-Plus'"
].concat(releaseDev === "release" ? ["--prod", "--release"] : []);
console.log(executable, arguments.join(" "));
const child = spawn(executable, arguments, {
stdio: "inherit"
});
child.on("close", () => resolve());
child.on("error", err => reject(err));
});
我在这里做错了什么?为什么它只忽略我的等号而添加命令的其余部分?
如果我运行 cordova run ios --target='iPhone-7-Plus'
该命令将执行并启动 7+ 模拟器,不会出现任何问题。
最佳答案
生成时,我必须添加 shell: true
才能使用我的操作系统的默认 shell。生成的 shell 会去除特殊字符。
const child = spawn(executable, arguments, {
stdio: "inherit",
shell: true
});
关于node.js child_process 生成忽略等号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46813473/