2016-04-20 12 views
5

私はSwiftコマンドラインスクリプトを作成できることを最近知った。コマンドライン「起動パスがアクセスできない」

私はそれを使って自分のXamarinプロジェクトを構築できるかどうかを確かめました。

残念ながら、私は次のエラーが発生しており、修正方法はわかりません。

***キャッチされない例外によりにアプリを終了 'NSInvalidArgumentExceptionは'、理由: '打ち上げパスアクセスできません'

ここでは私のスクリプトです:

#!/usr/bin/env swift 

import Foundation 

print("Building Script") 

let fileManager = NSFileManager.defaultManager() 
let path = fileManager.currentDirectoryPath 

func shell(launchPath: String, arguments: [String] = []) -> NSString? { 

    let task = NSTask() 
    task.launchPath = launchPath 
    task.arguments = arguments 

    let pipe = NSPipe() 
    task.standardOutput = pipe 
    task.launch() 

    let data = pipe.fileHandleForReading.readDataToEndOfFile() 
    let output = NSString(data: data, encoding: NSUTF8StringEncoding) 

    return output 
} 

if let output = shell("/Applications/Xamarin\\ Studio.app/Contents/MacOS/mdtool", arguments: ["-v build", "\"--configuration:Beta|iPhone\"", "MyApp.iOS.sln"]) { 
    print(output) 
} 

任意の考え?

答えて

4

私は問題は直接launchpathとして「/ binに/ bashの」を渡して試してみてください、そして含まmdtool

を実行するのではなく、あなたが実際にシェルを実行し、それがmdtoolを実行したいということだと思います引数文字列の一部としてのmdtoolへのパス。

+0

この 'shell("/bin/bash "、引数:["/Applications/Xamarin \\ Studio.app/Contents/MacOS/mdtool "、" -v build "、" \ " - configuration:Beta | iPhone \" "、" MyApp.iOS.sln "])'私はもう例外を取得します。代わりに '/ bin/bash:/ Applications/Xamarin \ Studio.app/Contents/MacOS/mdtool:そのようなファイルやディレクトリはありません 'というメッセージが表示されます。 – mgChristopher

+0

興味深い - スペースをエスケープする必要があるのだろうか?または、\\の代わりに単一の\が必要なのでしょうか?私はそれを試してみるか、スペースがないシンボリックリンクを作成しようとしますか? – Jason

+1

私はそれが働いている! 'shell( "/ bin/bash"、引数: "" -c "、"' /アプリケーション/ Xamarin Studio.app/Contents/MacOS/mdtool '-v build' --configuration:Beta | iPhone 'MyApp.iOS。あなたは助けが非常に貴重です。これについての答えを共有する最善の方法は何ですか? – mgChristopher

関連する問題