简体   繁体   English

Swift中的macOS终端模拟器

[英]macOS Terminal Emulator in Swift

I'm trying to create a Terminal emulator using the Swift Language (currently on Swift 4.0) 我正在尝试使用Swift语言创建终端仿真器(当前在Swift 4.0上)

So far I've created a UI and everything the only issue is that some of my commands don't work such as: 到目前为止,我已经创建了一个UI,所有唯一的问题是我的某些命令不起作用,例如:

diskutil mount disk0s1

which would give me the following error in the Xcode console output: 这将在Xcode控制台输出中给我以下错误:

"Could not start up a DiskManagement session"

Some commands work such as: 一些命令的工作方式如下:

echo Hi

Here is the code I have so far that actually does the command: 这是我到目前为止实际执行命令的代码:

@discardableResult
func shell(_ args: String) -> Int32 {
    let task = Process()
    task.launchPath = "/usr/bin/env"
    let cmd = args.characters.split(separator: " ").map(String.init)
    task.arguments = cmd
    task.launch()
    task.waitUntilExit()
    return task.terminationStatus
}

I figured it out after dwelling on this for 5 hours. 我在这里住了5个小时后才知道。 Within the entitlements file, you need to change App Sandbox to NO. 在权利文件中,您需要将“应用程序沙箱”更改为“否”。

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

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