简体   繁体   English

如何使用Process Class执行命令需要在MacOS中输入密码

[英]How to use Process Class to execute commands need to enter password in MacOS

I want to execute commands below by Process Class: 我想通过Process Class执行以下命令:

let uninstallTask = Process()
        uninstallTask.launchPath = "/bin/bash"
//MarkerPro is an app in launchpad
        uninstallTask.arguments = ["-c","sudo rm -rf "+"/Applications/MarkerPro.app"]
        uninstallTask.launch()

But get errors below: sudo: no tty present and no askpass program specified 但是得到以下错误:sudo:没有tty存在且没有指定askpass程序

So probably need to enter password before i execute delete command. 因此在执行delete命令之前可能需要输入密码。

I found the solution by using "STPrivilegedTask" which is a tool to get authorization by users. 我通过使用“STPrivilegedTask”找到了解决方案,这是一个获得用户授权的工具。 Using FileManager API I think also a good idea 使用FileManager API我认为也是一个好主意

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM