各位爹,请教一个 golang 的问题!

31次阅读

共计 300 个字符,预计需要花费 1 分钟才能阅读完成。

各位 golang 大佬(爹),上午好!我有个菜鸡问题:如何使用 golang 的 exec.Command() 函数执行 sudo?

背景:小弟在使用 chromedp 做一个爬虫,目前一切正常,唯一的遗憾就是每次运行之前需要手动在 macOS 的终端执行 sudo /Applications/Google Chrome.app/Contents/MacOS/Google Chrome --remote-debugging-port=19222 必须加 sudo 才能打开 chrome 调试窗口。因为 golang 可以执行终端命令,所以我想使用代码去唤醒调试窗口,但是测试下来好像无法全自动调用 sudo 命令(不输入密码或密码怎么传进去)。

正文完
 0