Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 995987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:48:30+00:00 2026-05-16T06:48:30+00:00

task = [NSTask new]; [task setLaunchPath:@/bin/sh]; [task setArguments:[NSArray arrayWithObject:@/applications/jarvis/brain/server.sh]]; [task setCurrentDirectoryPath:@/]; NSPipe *outputPipe =

  • 0
task = [NSTask new];
[task setLaunchPath:@"/bin/sh"];
[task setArguments:[NSArray arrayWithObject:@"/applications/jarvis/brain/server.sh"]];
[task setCurrentDirectoryPath:@"/"];

NSPipe *outputPipe = [NSPipe pipe];
[task setStandardInput:[NSPipe pipe]];
[task setStandardOutput:outputPipe];

[task launch];

NSMutableString *outputString = [NSMutableString string];
while ([outputString rangeOfString:@"Jarvis>"].location == NSNotFound) {
    [outputString appendString:[[[NSString alloc] initWithData:[[outputPipe fileHandleForReading] readDataToEndOfFile] encoding:NSUTF8StringEncoding] autorelease]];
     }

NSArray* substrings = [outputString componentsSeparatedByString:@"Jarvis>"];
NSString* finalCharlieOutputNSTask = [substrings lastObject];
NSSpeechSynthesizer * syn = [[NSSpeechSynthesizer alloc] init];
[syn startSpeakingString:finalCharlieOutputNSTask]; 
self.charlieOutput.stringValue = finalCharlieOutputNSTask;

Ok, so that’s my code. It launches an SH file and reads the output. BUT, I want it to wait until “Jarvis>” appears in the string before saying and printing the result. But, it seems like with the while loop, my code freezes there. Without it it reads the normal output of launching the server.sh file, but the whole thing. Any ideas why this doesn’t work?

Here is the Server.sh file:

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T06:48:31+00:00Added an answer on May 16, 2026 at 6:48 am

    Elijah, edit your code to look like this:

    ...
    [task launch];
    
    NSMutableString *outputString = [NSMutableString string];
    while ([outputString rangeOfString:@"Jarvis>"].location == NSNotFound) {
        [outputString appendString:[[[NSString alloc] initWithData:[[outputPipe fileHandleForReading] readDataToEndOfFile] encoding:NSUTF8StringEncoding] autorelease];
    }
    
    if ([task isRunning]) {
        [task terminate];
    }
    
    NSArray *subStrings = [outputString componentsSeparatedByString:@"Jarvis>"];
    ...
    

    This code within the loop will successively read output data from your file and append it to the current output, and stop reading when @”Jarvis>” is found (it will also kill the task after a @”Jarvis>” is found, so it doesn’t keep running forever).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my code: task = [[NSTask alloc] init]; [task setCurrentDirectoryPath:@/applications/jarvis/brain/]; [task setLaunchPath:@/applications/jarvis/brain/server.sh]; NSPipe
I tried this code NSTask *task; task = [[NSTask alloc] init]; [task setLaunchPath: @/usr/bin/ping];
This code is used to get stdout of the process NSTask * task; NSPipe
Task: To provide facility to upgrade the system remotely or add new features. What
the task I want to achieve is import XML file into SQL Server. Once
I need a bit of help with NSTask. Also, I am new to Cocoa
I am trying to terminate an openvpn task, spawned via NSTask. My question: Should
Using below code, I am getting this error: NSTask: Task create for path '/Users/media/Library/Developer/Xcode/DerivedData/Manager-gnixeptcszdoubbnfcncumzypwge/Build/Products/Debug/lib'
I'm running /usr/bin/perl or /usr/bin/php via an NSTask and want to retrieve the HTTP
I'm using NSTask, but when I launch the task it blocks the main thread

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.