On Tuesday, December 9, 2014, Ken Thomases <k...@codeweavers.com> wrote:

> On Dec 9, 2014, at 8:24 AM, SevenBits <sevenbitst...@gmail.com
> <javascript:;>> wrote:
>
> > Do you know how to trigger the automatic flushing of standard output
> like you described? There doesn't seem to be anything in NSTask to do it,
> though it probably wouldn't be there anyway. Is it perhaps a C function
> call? I do apologize for asking a basic question, but the Internet is full
> of people wanting to get the results of a BSD-layer command, and not
> through communicating with the process via a Terminal-like interface, and
> my Google-fu is not up to the task.
>
> The only way to make it automatic is to have the standard input connected
> to a terminal device.  For communication between two processes, you would
> use a pseudo-terminal device:
>
>
> https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man4/pty.4.html
>
> https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man3/openpty.3.html
>
>
I actually just figured this out, but those are great; I'll certainly take
a look at them. I haven't done really low-level C stuff like that for some
time, which is why I couldn't remember the functions.


> However, that brings with it the requirement that you emulate a terminal.
> The subprocess will be able to detect that it's connected to a terminal and
> may attempt to do terminal-like things, which the parent process would have
> to expect and respond to.  That's a complicated mess.


I control the source code to the tool that is being called, and I have
modified it to make sure that no such calls are being made. This is a very
simple console application; if it needed ncurses or something of that sort
I'd be panicking right now.


>
> If you are building the command-line tool from source, then I recommend
> that you have it use setvbuf() to set standard output to line buffered.
> And, any place where it tries to read from standard input, call fflush() to
> flush standard output first.


Okay, thanks for the advice. I have noticed one small issue: my app
receives from the process and prints back all of the app's input. That, and
the app's outputs are buffered, so in some cases it takes a while for its
output to reach my "terminal", making it appear to be hanging, but that's a
minor issue.


>
> Regards,
> Ken


Thanks a lot everyone'

-- SevenBits
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to