Je dois exécuter un fichier .sh et obtenir sa sortie. J'ai aussi besoin de voir la configuration du fichier. Le fichier .sh exécute simplement une application java via le terminal.Comment exécuter un fichier .sh à l'aide de NSTask et obtenir sa sortie?
Des idées? Je suis vraiment coincé sur ce .....
Elijah
Le fichier server.sh:
echo Starting Jarvis Program D.
ALICE_HOME=.
SERVLET_LIB=lib/servlet.jar
ALICE_LIB=lib/aliceserver.jar
JS_LIB=lib/js.jar
# Set SQL_LIB to the location of your database driver.
SQL_LIB=lib/mysql_comp.jar
# These are for Jetty; you will want to change these if you are using a different http server.
HTTP_SERVER_LIBS=lib/org.mortbay.jetty.jar
PROGRAMD_CLASSPATH=$SERVLET_LIB:$ALICE_LIB:$JS_LIB:$SQL_LIB:$HTTP_SERVER_LIBS
java -classpath $PROGRAMD_CLASSPATH -Xms64m -Xmx128m org.alicebot.server.net.AliceServer $1
Mon code actuel:
NSTask *server = [NSTask new];
[server setLaunchPath:@"/bin/sh"];
[server setArguments:[NSArray arrayWithObject:@"/applications/jarvis/brain/server.sh"]];
NSPipe *outputPipe = [NSPipe pipe];
[server setStandardInput:[NSPipe pipe]];
[server setStandardOutput:outputPipe];
[server launch];
NSMutableString *outputString = [NSMutableString string];
while ([outputString rangeOfString:@"Jarvis>"].location == NSNotFound) {
[outputString appendString:[[[NSString alloc] initWithData:[[outputPipe fileHandleForReading] readDataToEndOfFile] encoding:NSUTF8StringEncoding] autorelease]];
NSRunAlertPanel(@"", outputString, @"", @"", @"");
}
Le NSRunAlertPanel est juste pour vérifier la sortie. Maintenant, mon code se fige et ne parvient même pas au panneau d'alerte.
Oui. Est-ce que tout cela et il retourne l'écho au début sur le fichier .sh, mais pas l'installation ou le programme final. Il y a également un champ de saisie utilisateur. – objectiveccoder001
Pouvez-vous poster un aperçu de votre script shell? – sakra
oui. Je l'ai mis dans ma question. – objectiveccoder001