Running command from Cocoa freezes my app
<p>I use this code to run a command from the Cocoa Application:</p>

<pre><code>extension String {
    func runAsCommand() -&gt; String {
        let pipe = NSPipe()
        let task = NSTask()
        task.launchPath = "/bin/sh"
        task.arguments = ["-c", String(format:"%@", self)]
        task.standardOutput = pipe
        let file = pipe.fileHandleForReading
        task.launch()
        if let result = NSString(data: file.readDataToEndOfFile(), encoding: NSUTF8StringEncoding) {
            return result as String
        }
        else {return "--- Unable to initialize string from file data ---"}
    }
}
</code></pre>

<p>Example:</p>

<pre><code>"command".runAsCommand()
</code></pre>

<p>The problem is, that this freezes my application. For example, if the command is to open some other app, such as Firefox, it freezes my host app until Firefox is exited. I don't want that behaviour. What should I do?</p>