2010-08-12 71 views

回答

1
[NSTask launchedTaskWithLaunchPath:@"thisCMD" arguments:[NSArray arrayWithObject:username]]; 

或者,如果username是不是已經是一個字符串:

[NSTask launchedTaskWithLaunchPath:@"thisCMD" arguments:[NSArray arrayWithObject:[username description]]]; 

或者,如果你希望能夠改變格式說明每個參數的東西多了以後複雜:

[NSTask launchedTaskWithLaunchPath:@"thisCMD" arguments:[NSArray arrayWithObject:[NSString stringWithFormat:@"%@", username]]]; 
+0

讓我們說命令someCommand usernameShouldBeHere anotherparam我該怎麼做呢? – Daniel 2010-08-12 04:10:51

+0

將'thisCMD'更改爲'someCommand'並使用'arrayWithObjects'構造函數構造'NSArray'。 – David 2010-08-12 04:19:35