discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problems with NSPipe


From: Noah Roberts
Subject: Problems with NSPipe
Date: Wed, 3 Dec 2003 11:06:55 -0800 (PST)

I am trying to communicate with an external program through an NSPipe and
am having much trouble.  The external program works and destroys the input
buffer through the C++ command cin.rdbuf()->pubsetbuf(NULL, 0).  The
problem appears to be somewhere in this code:

-(void)sendToEngine:(ThinkCommand*)think
{
  NSData *endl = [NSData dataWithBytes:"\n" length:1];
  [[engineInputPipe fileHandleForWriting] writeData:[[think posString]
dataUsingEncoding:NSASCIIStringEncoding]];
  [[engineInputPipe fileHandleForWriting] writeData:endl];
  [[engineInputPipe fileHandleForWriting] synchronizeFile];

  NSLog(@"Sent position");
  [[engineInputPipe fileHandleForWriting] writeData:[[think goString]
dataUsingEncoding:NSASCIIStringEncoding]];
  [[engineInputPipe fileHandleForWriting] writeData:endl];
  [[engineInputPipe fileHandleForWriting] synchronizeFile];
  [[engineInputPipe fileHandleForWriting] writeData:endl];
  [[engineInputPipe fileHandleForWriting] synchronizeFile];
  NSLog(@"Sent go");
  currentThink = think;
  //engineThinking = YES;
}

Calling this method the first time results in the position arriving at the
engine (it outputs this fact to stderr).  Future calls result in the rest
of the data from the previous call arriving at the engine and then the
position command from the current call.  I frankly do not understand why
this is happening but am guessing that synchronizeFile is not flushing
output as I expect it should.

The above input pipe has been set as the NSTask's standardInput.

Any input and/or hints is greatly appreciated.

NR






reply via email to

[Prev in Thread] Current Thread [Next in Thread]