我想在我的程序中运行终端命令。该命令如下所示:
cd /path/to/file/; ./foo HTTPProxy 127.0.0.1
它适用,system()
但当我使用NSTask
.
system("cd /path/to/file/; ./foo HTTPProxy 127.0.0.1");
工作正常,但
NSTask *task = [[NSTask alloc] init];
[task setLaunchPath:@"/path/to/file/./foo"];
NSPipe *pipe = [NSPipe pipe];
[task setStandardOutput:pipe];
NSFileHandle *file = [pipe fileHandleForReading];
[task setArguments:[NSArray arrayWithObjects:@"HTTPProxy 127.0.0.1", nil]];
[task launch];
NSData *data = [file readDataToEndOfFile];
NSString *string = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
NSLog(string);
没有。输出:
Command-line option 'HTTPProxy 127.0.0.1' with no value. Failing.
有人有想法吗?