• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Opening an Embedded Application in Terminal
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Opening an Embedded Application in Terminal


  • Subject: Re: Opening an Embedded Application in Terminal
  • From: SevenBits <email@hidden>
  • Date: Tue, 09 Dec 2014 19:00:44 -0500

On Tuesday, December 9, 2014, Ken Thomases <email@hidden> wrote:

> On Dec 9, 2014, at 8:24 AM, SevenBits <email@hidden
> <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 (email@hidden)

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:

This email sent to email@hidden


References: 
 >Re: Opening an Embedded Application in Terminal (From: Ken Thomases <email@hidden>)
 >Re: Opening an Embedded Application in Terminal (From: Ken Thomases <email@hidden>)

  • Prev by Date: over 200 warnings when building a lib
  • Next by Date: What triggers -applicationDidChangeScreenParameters: delegate method?
  • Previous by thread: Re: Opening an Embedded Application in Terminal
  • Next by thread: Using AV Foundation to record m3u8 stream to disk
  • Index(es):
    • Date
    • Thread