开发者

Run Shell Command with custom input

开发者 https://www.devze.com 2023-01-11 09:48 出处:网络
How can i run a shell c开发者_高级运维ommand in objective c with a variable E.G system(\"thisCMD thisParam %@\", username);[NSTask launchedTaskWithLaunchPath:@\"thisCMD\" arguments:[NSArray arrayWithO

How can i run a shell c开发者_高级运维ommand in objective c with a variable E.G system("thisCMD thisParam %@", username);


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

Or if username isn't already a string:

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

Or if you want to be able to change the format specifier for each argument to something more complicated later:

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

精彩评论

暂无评论...
验证码 换一张
取 消