guitarflow
guitarflow

Reputation: 2970

Sending EOF to NSTask via NSPipe or NSFileHandle

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!

Upvotes: 0

Views: 770

Answers (1)

Martin R
Martin R

Reputation: 539735

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];

Upvotes: 5

Related Questions