CocoaDev

Edit AllPages

I am trying to write a wrapper for a command line tool that requires user input after launch. I have set up the pipes to and from the NSTask object. My problem is that when it asks for the first input I can pass that no problem but when it requests the next it immediately sends the text “Uncaught Exception End_of_File” to the output pipe and exits. My thinking was that the “close file” statement in my code (below) could be the cause (i.e. its attempting to read input from the closed file handle and getting the end of file) however, as far as i can fathom, this is required to trigger the end of the input.

Does anyone have any pointers?

Here is the code (was intended as a side to get it working before incorporating it into my main program so my apologies for its roughness!)

}

}

Any help much appreciated! -DG


When you close the standard input you can no longer write to it. That’s what close means.

If Unison is looking for a return character to delimit input, then you should probably add one. Currently you’re writing a line but no return character, so it has no idea that you’re done sending it input. When you close the file it’s obvious, but this prevents you from re-using the task.

One other note: you read pieces of incoming data and convert them to UTF-8 before appending them to your output. This is dangerous. The way UTF-8 works, it’s possible for a slice of valid UTF-8 data to not be valid UTF-8. To be completely safe, you should buffer the incoming data (in an NSMutableData, for example) and then only break it into pieces where you see a known safe delimeter such as a ‘\n’ in the data. Another possibility is to write a parser that knows enough about UTF-8 to pick out safe character boundaries anywhere, it’s not that hard, but you shouldn’t need it if your task produces a lot of reasonable-length lines as most UNIX tools tend to do.


OK, as i thought it then, i had been trying to just send the return character, but it had not been working. Turns out that the UNIX tool was attempting to modify the terminal environment to operate with single charicter input without a return character required. Operating the tool in “dumb” mode solved this one!

Thanks also for your other input. Much appreciated! - DG