node.js child_process spawn忽略等号
问题描述:
我试图用目标设备启动cordova命令。我测试过这个命令并且它可以工作,但是当我尝试用我的代码生成它时,它忽略了等号,因此不会运行。此代码确实与另外的"--target='iPhone-7-Plus"
node.js child_process spawn忽略等号
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
为了使用我的操作系统的默认外壳。产卵使用的外壳将去除特殊字符。
const child = spawn(executable, arguments, {
stdio: "inherit",
shell: true
});
我在该行看到''--target ='iphone-7-plus“',这可能是问题吗? –
@DavidGatti我不好,我抄了错。在我的代码中它确实有'''和runnning'cordova运行ios --target ='iPhone-7-Plus''直接输入到命令行时没有问题执行。 –
我建议您更新问题。那么在数组'buildOnly中删除这个if else语句形式呢? “构建”:“运行”,“一些核心的方法去做这件事,我也会做'console.log'的console.log,然后再传递给Spaw,看看它是如何处理你在那里的操作。 –