我有一個可可應用程序,我想啓動一個啓動Node.js的shell腳本。我想我會這樣做與NSTask使用NSTask啓動啓動Node.JS的shell腳本
NSTask *task = [[NSTask alloc] init];
[task setLaunchPath:@"/bin/bash/start.sh"];
[task setArguments:[NSArray arrayWithObjects:@"start.sh", nil]];
[task setStandardOutput:[NSPipe pipe]];
[task setStandardInput:[NSPipe pipe]];
[task launch];
腳本是在我的應用程序的根。我嘗試了很多發射路徑的變化,並且我被卡住了。任何幫助將不勝感激!
編輯:
這裏是我的新代碼,我設置參數。由於某些原因,它仍然不起作用。
NSTask *task = [[NSTask alloc] init];
[task setLaunchPath:@"/bin/bash"];
[task setArguments:[NSArray arrayWithObjects:[[NSBundle mainBundle] pathForResource:@"start" ofType:@"sh"], nil]];
[task launch];
我編輯我的答案,我設置參數和更改路徑。它仍然無法工作。 –
pathForResource:我認爲它是錯誤的。這些文檔讓我很難理解如何獲得正確的路徑。 –
@MinaDawoud:以什麼方式? –