Usando Pandoc con Swift

Estoy tratando de usar Pandoc para convertir LaTeX a Markdown. Necesito crear un archivo y luego ejecutar el comando de terminal pandoc. El problema es que el archivo que creo no está en el mismo directorio en el que estoy ejecutando los comandos del terminal.

Intenté usar shell ("cd") pero no te mueve a la carpeta del usuario.

¿Algunas ideas?

import Cocoa

class ViewController: NSViewController {

    func shell(args: String...) -> Int32 {
        let task = NSTask()
        task.launchPath = "/usr/bin/env"
        task.arguments = args
        task.launch()
        task.waitUntilExit()
        return task.terminationStatus
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        shell("pwd")

        let file = "input.txt"
        let text = "\\emph{test}"

        if let dir : NSString = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.AllDomainsMask, true).first {
            let inputPath = dir.stringByAppendingPathComponent(file)

            //writing
            do {
                try text.writeToFile(inputPath, atomically: false, encoding: NSUTF8StringEncoding)
                shell("pandoc","-f","latex","-t","markdown","input.txt","-o","output.txt")
            }
            catch {/* error handling here */}

            let outputPath = dir.stringByAppendingPathComponent("output.txt")
            //reading
            do {
                let inputText = try NSString(contentsOfFile: inputPath, encoding: NSUTF8StringEncoding)
                print(inputText)

                let convertedText = try NSString(contentsOfFile: outputPath, encoding: NSUTF8StringEncoding)
                print(convertedText)

            }
            catch {/* error handling here */}
        }


    }

    override var representedObject: AnyObject? {
        didSet {
        // Update the view, if already loaded.
        }
    }


}

Aquí está la salida

/Users/james/Library/Developer/Xcode/DerivedData/FlashCardPreview-gqzwutewnxspazcdloxqruaikvel/Build/Products/Debug
env: pandoc: No such file or directory
\emph{test}

Respuestas a la pregunta(1)

Su respuesta a la pregunta