AMShellWrapper отправка данных в запущенную задачу - PullRequest
0 голосов
/ 22 августа 2010

Я нахожусь в процессе преобразования AMShellWrapper в мое собственное приложение, которое запускает SH-файл с пользовательскими данными Поэтому мне нужно отправить данные в работающую задачу.

Есть идеи?

Элайджа

1 Ответ

0 голосов
/ 04 сентября 2010

Вам нужен несколько иной подход, аналогичный PseudoTTY.app !

/*
code added to PseudoTTY/PtyView.m

sources:
- PseudoTTY.app, http://amath.colorado.edu/pub/mac/programs/PseudoTTY.zip
- charliebot/server.sh, http://sourceforge.net/projects/charliebot/
  (note: modify server.sh to accept complete paths; see: 
   /3017116/noclassdeffounderror-pri-zapuske-stsenariya-obolochki)
*/

@interface PtyView (PtyPrivate)
-(int)count: (NSString *) str;
...
@end

@implementation PtyView (PtyPrivate)

-(int)count: (NSString *) str {
   static int counter = 0;
   if (   
     ([str rangeOfString:@"Charlie>"].location != NSNotFound ) || \
     ([str rangeOfString:@"[Charlie] user>"].location != NSNotFound )
   )
  {
     counter++;
  }
  return counter;
}

-(void)startTask
{
   NSString * cmd = @"/path/to/charliebot/server.sh";
   //NSString * cmd = @"/bin/sh";
   ...
   [self insertText: @"\n\n"];
}

-(void) didRead: (NSNotification *)noty
{
   NSData * data = [[noty userInfo] objectForKey:NSFileHandleNotificationDataItem];

   if ([data length] == 0)
      return; // end of file

   NSString * str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

   int printvar = [self count: str];

   if   (printvar < 1 )
   {
      [self insertText: @"."];
      [str release];
      [[noty object] readInBackgroundAndNotify];
   }else if (printvar == 1) {
      [self insertText: @"\n\n"];
      [self insertText: str];
      [str release];
      [[noty object] readInBackgroundAndNotify];
   }else {
      [self insertText: str];
      [str release];
      [[noty object] readInBackgroundAndNotify];
   }
}

@end
...