0

I have an NSTask which processes arguments passed from stdin. The arguments are passed via NSFileHandle.

It's working fine, but our command line tool reads input from stdin until it receives the EOF symbol (by pressing Ctrl+C).

I don't think I can add the EOF symbol to an ASCII string, so what would be the options? Any feedback appreciated!

Thanks in advance!

guitarflow
  • 2,930
  • 25
  • 38
  • Ctrl-c isn't EOF; it's SIGINT (interrupt). Moreover, EOF isn't a character; it's the End Of File. So, to “send EOF”, you just end the file. – Peter Hosey Jul 19 '13 at 19:39
  • @PeterHosey Technically, there is indeed a EOF character defined by ASCII, and it's been in use. But sending that char into the file won't help on a Mac, admittedly. – Thomas Tempelmann Oct 18 '19 at 22:39
  • Ah yes, the End of Transmission character—also known as Ctrl-D. https://en.wikipedia.org/wiki/End-of-Transmission_character – Peter Hosey Apr 09 '20 at 14:27

1 Answers1

5

Calling closeFile on the writing end of the pipe signals the EOF condition:

NSPipe *inPipe = [NSPipe new];
[task setStandardInput:inPipe];

[[inPipe fileHandleForWriting] writeData:...];
// ...
[[inPipe fileHandleForWriting] closeFile];
Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382