child_process.spawn 参数传输的问题
发布于 7 年前 作者 p2227 3465 次浏览 来自 问答

我本地有一个https服务,访问网址是 https://127.0.0.1:8080/

然后在命令行中直接敲

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --host-rules="MAP xxx.asdf:443 127.0.0.1:8080" --ignore-certificate-errors --incognito https://xxx.asdf://xxx.asdf

是会打开一个隐身窗口,并且打开 https://xxx.asdf ,然后内容是我 https://127.0.0.1:8080/ 的那网站

但是如果换成以下代码

const child_process = require('child_process');

child_process.spawn(
	`/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome`,
	[
		`--host-rules="MAP xxx.asdf:443 127.0.0.1:8080"`,
		`--ignore-certificate-errors`,
		`--incognito`,
		`https://xxx.asdf`
	]
)

然后通过node去运行,会打开一个隐身窗口,但是会提示找不到 https://xxx.asdf 的ip地址,即无法访问

初步看来是因为spawn运行的和直接在命令行里面敲有点不一样,大家知道怎么改node的代码达到跟命令行一样的效果吗?

1 回复

是妹子么?是妹子我就告诉你 spawn.stdout.on(‘data’, function (data) { console.log(‘标准输出:\n’ + data); }); 如果答错了你也不要怪我我只是个路过的谐星

回到顶部