从 java 代码在 MAC OS 上运行 .pkg
我正在尝试从我的 java 代码运行 .mpkg 应用程序:
public void runNewPkg(){ try { String command = "sudo installer -pkg Snip.mpkg -target /Applications"; Process p = Runtime.getRuntime().exec(command); System.out.println(p.getErrorStream()); } catch (Exception ex) { ex.printStackTrace(); } }
并且出现以下错误,并且我的终端窗口挂起。
java.lang.UNIXProcess$DeferredCloseInputStream@2747ee05
Password:
Sumit-Ghoshs-iMac-3:downloads sumitghosh3$ Password:
Password:
-bash: **********: command not found
Sumit-Ghoshs-iMac-3:downloads sumitghosh3$
- 我认为我还需要提供密码才能从命令行运行 pkg 你能告诉我该怎么做吗?
Am trying to run a .mpkg application from my java code :
public void runNewPkg(){ try { String command = "sudo installer -pkg Snip.mpkg -target /Applications"; Process p = Runtime.getRuntime().exec(command); System.out.println(p.getErrorStream()); } catch (Exception ex) { ex.printStackTrace(); } }
And am getting the following error and my terminal window hangs..
java.lang.UNIXProcess$DeferredCloseInputStream@2747ee05
Password:
Sumit-Ghoshs-iMac-3:downloads sumitghosh3$ Password:
Password:
-bash: **********: command not found
Sumit-Ghoshs-iMac-3:downloads sumitghosh3$
- I Think i need to provide the password also to run the pkg from the command line
Could you tell me how i can do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以向 sudo 提供密码:
上面的命令以 root 权限运行“cal -y 2011”。
You can provide the password to sudo:
The command above runs 'cal -y 2011' with root permissions.
我实际上会尝试编辑 /etc/sudoers 文件以不提示输入密码。如果您使用 NOPASSWD 标签,您应该能够做到这一点。一个示例条目是:
I would actually try editing your /etc/sudoers file to not prompt for a password. If you use the NOPASSWD tag, you should be able to do that. An example entry would be:
如果您想要一个用于提升权限的交互式解决方案,我已使用
openscript
来提升包装的 shell 脚本的权限。它是这样的:如果
withPrivilege
标志为 true,则会出现一个密码对话框。未显示的是createTmpScript()
,它在/tmp
中创建可执行文件,以及StreamReader
,它扩展了Thread
并且是用于捕获stdout
和stderr
流。If you want an interactive solution for elevating privilege, I have used
openscript
to elevate privilege of a wrapped shell script. It goes something like this:If
withPriviledge
flag is true, a password dialog will be raised. Not shown iscreateTmpScript()
which creates an executable file in/tmp
, andStreamReader
which extendsThread
and is used to capture bothstdout
andstderr
streams.