'Could not start up a DiskManagement session
I wanted to eject a pendrive using Swift.
First I get the name of the pendrive by inspecting the "Volumes" folder.
Before trying to eject it, I wanted to make sure the code I was using was correct. For this reason I tried to execute a diskutil list command using this script:
let task = Process()
let pipe = Pipe()
task.standardError = pipe
task.standardOutput = pipe
task.executableURL = URL(fileURLWithPath: "/usr/sbin/diskutil")
task.arguments = [""]
task.launch()
let data = pipe.fileHandleForReading.readDataToEndOfFile()
let output = String(data: data, encoding: .utf8)!
print(output)
The output I get is "Could not start up a DiskManagement session". But if I change this lines
task.executableURL = URL(fileURLWithPath: "/bin/zsh")
task.arguments = ["-c", "echo hello"]
it prints the right output ("hello").
I get the same error if I try to use
task.executableURL = URL(fileURLWithPath: "/bin/zsh")
task.arguments = ["-c", "diskutil list"]
Any solution?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
