我想在swift中编译一个latex文件,如果应用程序有App Sandbox OFF,我可以编译该文件。
如果我打开App Sandbox并尝试编译,我会收到错误:"启动路径无法访问"
如何在App Sandbox打开的情况下运行pdflatex命令来编译latex文件?
以下是我使用的方法,它适用于App Sandbox关闭。
let latexCmd = "/Users/user/Desktop/test/article.tex"
let logText:String = self.runTerminal(command: latexCmd)
func runTerminal(command: String)->String{
let pipe:Pipe = Pipe()
let task:Process = Process()
task.launchPath = "/Library/TeX/texbin/pdflatex"
task.arguments = ["-file-line-error", "-interaction=nonstopmode", "-synctex=1", command]
task.standardOutput = pipe
task.currentDirectoryPath = "/Users/user/Desktop/test"
task.launch()
let data = pipe.fileHandleForReading.readDataToEndOfFile()
let output = String(data: data, encoding: String.Encoding(rawValue: String.Encoding.utf8.rawValue))
return output!
}