我尝试使用 cat 命令连接文件。当我在终端中使用它时,一切正常:
cat /Users/Home/Desktop/test.mp3* > test.mp3
尝试使用 NSTask 重现此问题,出现以下错误:
代码 :
NSArray *Args = [NSArray arrayWithObjects:[NSString stringWithFormat:@"%@*",[TAFileName stringByDeletingPathExtension]],@">",[TAFileName stringByDeletingPathExtension],nil];
NSLog(@"%@",Args);
NSString *LaunchPath = [[NSBundle mainBundle] pathForResource:@"cat" ofType:@""];
[self startTaskWithLaunchPath:LaunchPath andArguments:Args showingProcess:NO];
NSLog 输出:
(
"/Users/Home/Desktop/test.mp3*",
">",
"/Users/Home/Desktop/test.mp3"
)
错误 :
cat: /Users/Home/Desktop/test.mp3*: No such file or directory
cat: >: No such file or directory
cat: /Users/Home/Desktop/test.mp3: No such file or directory
“startTaskWithLaunchPath:andArguments:showingProcess:”可以与许多其他终端命令一起正常工作,我 100% 确定这不是问题。