【发布时间】:2010-08-17 19:00:59
【问题描述】:
这是我的代码:
NSTask *setupTask = [NSTask new];
[setupTask setLaunchPath:@"/bin/sh"];
[setupTask setArguments:[NSArray arrayWithObject:@"/applications/jarvis/brain/server.sh"]];
[setupTask setCurrentDirectoryPath:@"/"];
NSPipe *outputPipeSetup = [NSPipe pipe];
[setupTask setStandardInput:[NSPipe pipe]];
[setupTask setStandardOutput:outputPipeSetup];
[setupTask launch];
NSTask *aliceTask = [NSTask new];
[aliceTask setLaunchPath:@"/usr/bin/java"];
[aliceTask setArguments:[NSArray arrayWithObjects:@"-classpath", @"/applications/jarvis/brain/", @"-Xms64m", @"-Xmx128m", @"org.alicebot.server.net.AliceServer", nil]];
NSPipe *aliceInputPipe = [NSPipe pipe];
[aliceTask setStandardInput:aliceInputPipe];
NSPipe *aliceOutputPipe = [NSPipe pipe];
[aliceTask setStandardOutput:aliceOutputPipe];
[aliceTask launch];
NSMutableString *outputString = [NSMutableString string];
while ([outputString rangeOfString:@"Jarvis>"].location == NSNotFound) {
[outputString appendString:[[[NSString alloc] initWithData:[[aliceOutputPipe fileHandleForReading] readDataToEndOfFile] encoding:NSUTF8StringEncoding] autorelease]];
}
但是,outputString 什么都不返回,并且卡在 while 循环中。这是 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
【问题讨论】:
-
疯了!为什么要从编译的目标 c 调用 Java?
-
如果我要解释这将花费我几个小时!:D 但简单地说,我想为 ALICE AI 制作一个 Objective-c 图形用户界面。 AIML 解释器是用 java 编写的。在终端中,我只需启动 .sh 文件,它会加载 ALICE 并为我提供一个用于用户输入和 Alice 响应的字段。我稍后会在我的代码中解析它。
标签: java objective-c nstask alice