I am currently running it as follows, but when the password is incorrect, the application gets stuck.
swift
let task=NSTask.launchedTaskWithLaunchPath("/bin/sh", arguments: ["-c", "/AAAA.sh", "sleep3")
task.waitUntilExit()
AAAA.sh
echo "password" | sudo-Sapachectl start
To avoid this,
Could you tell me one of the following?
swift macos
Check the terminationStatus
to see if the shell script was successful.
However, this alone will not determine whether the password was incorrect or subsequent command execution failed.
let task=NSTask.launchedTaskWithLaunchPath("/bin/sh", arguments: ["-c", "/AAAA.sh")
task.waitUntilExit()
if task.terminationStatus!=0{
// failure
}
If you want to determine if the password is wrong first, how about running only the dummy sudo
to check the terminationStatus
first?
echo "password" | sudo-St true
© 2024 OneMinuteCode. All rights reserved.