AMShellWrapper 将数据发送到正在运行的任务

发布于 2024-09-15 20:32:51 字数 179 浏览 2 评论 0原文

我正在将 AMShellWrapper 转换为我自己的运行 SH 文件的应用程序有用户输入。因此,我需要将数据发送到正在运行的任务。

有什么想法吗?

以利亚

I'm in the process of converting AMShellWrapper to my own application that runs an SH file that has userinput. Therefore, I need to send data to a running task.

Any ideas?

Elijah

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伪心 2024-09-22 20:32:51

您需要一种与 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: 
   http://stackoverflow.com/questions/3540269/noclassdeffounderror-when-running-shell-script)
*/

@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

You need a somewhat different approach along the lines of 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: 
   http://stackoverflow.com/questions/3540269/noclassdeffounderror-when-running-shell-script)
*/

@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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文