2012-10-17 61 views
0

可能重複:
NSTask launch path not accessibleNSTask啓動路徑錯誤

任何想法,爲什麼叫這個,

NSTask *buildMTask = [[NSTask alloc] init]; 
[buildMTask setLaunchPath:@"/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\\ Simulator.app/Contents/MacOS/iPhone\\ Simulator"]; 
[buildMTask launch]; 

結果

'啓動路徑無法訪問' ?

謝謝!

+0

你爲什麼要逃離空間角色?它應該是一個文件的路徑,因此空間不應該逃脫 – Petesh

+0

它沒有任何區別,如果空格被轉義或沒有...發生同樣的錯誤... – Tronic

+0

http:///stackoverflow.com/questions/3221432/nstask-launch-path-not-accessible是關於啓動一個shell腳本,所以我不認爲它是重複的。 –

回答

1
NSString *appname = @"/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone Simulator.app/Contents/MacOS/iPhone Simulator"; 
NSTask *aTask = [[NSTask alloc] init]; 
[aTask setLaunchPath:appname]; 
BOOL exists = [[NSFileManager defaultManager] isExecutableFileAtPath:[aTask launchPath]]; 
NSLog(@"%@ '%@'\n", exists ? @"Exists" : @"Does Not Exist", [aTask launchPath]); 
[aTask launch]; 

工作正常,甚至記錄可執行文件存在。刪除可執行文件中的\\ - 全部。

我建議在嘗試運行應用程序之前使用可執行存在檢查。

+0

如果它不可執行,那我們該怎麼做?在運行時運行chmod? – Itachi

+0

NSTask將可執行文件作爲第一個選項,如果所討論的項目不是可執行文件,那麼您應該問*爲什麼*。如果只是它是一個腳本,並沒有設置爲可執行文件,那麼請按照答案的建議將此問題標記爲重複項。如果它在應用程序包中,並且未標記爲可執行文件,那麼您的構建不正確。 – Petesh