Je souhaite exécuter une commande Terminal dans mon programme. La commande ressemble à ceci:Exécuter une commande de terminal avec NSTask
cd /path/to/file/; ./foo HTTPProxy 127.0.0.1
Il fonctionne avec system()
mais il ne fonctionne pas quand je l'utilise NSTask
.
system("cd /path/to/file/; ./foo HTTPProxy 127.0.0.1");
fonctionne très bien, mais
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);
ne fonctionne pas. Sortie:
Command-line option 'HTTPProxy 127.0.0.1' with no value. Failing.
Quelqu'un at-il une idée?
Non, même erreur ... – ahee
OUI Merci beaucoup, ça marche maintenant !!! – ahee