• 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: Debugging Stdout
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Debugging Stdout


  • Subject: Re: Debugging Stdout
  • From: Alastair Houghton <email@hidden>
  • Date: Wed, 5 Oct 2005 10:29:58 +0100

On 5 Oct 2005, at 00:25, Ronnie O wrote:


Thanks for all the suggestions, before I comment on any of them, I
found something pretty significant.

If I make the call to the c command line utility from my cocoa app, a
debug file is created.  If I check the debug file before I close the
cocoa app, it is only half-way created.  It stops right before where
it should print the stdin data.  So I make calls to the c program and
nothing appears in my textView.  Once I close the cocoa app and check
the debug file, it then has been fully created.  It contains a print
of the stdin text data and appears correct and complete.  I don't
think I had ever previously checked the debug file in mid-processing
and didnt realize my task wasnt running to completion until I closed
the cocoa app.  This is why I wasnt receiving any data returned from
stdout to my textView.  Does this behavior raise any flags??  As I
stated previously, the perl script is having no issues with my
existing code.  Why isnt my c task running to completion until I
terminate my cocoa app??


Probably because you aren't emptying one of the pipes you're using. If an application writes to a pipe and the pipe buffer (usually pretty small) becomes full, it is put to sleep until the owner of the other end of the pipe removes data from the buffer. If you aren't emptying all of the pipes you are using, then the application may block.


Equally, the block could occur in the other direction; if the other program is using buffered I/O, it might be that it's waiting for input, having put all of the required output into its buffers (that's why I suggested getting it to turn off output buffering). The solution here is either to get it to use unbuffered output, to provide extra input as necessary, or to close the input pipe, which will usually cause programs to terminate (which flushes output buffers).


In response to the previous possible solutions:

1) I had already included this:

[environment setObject:@"YES" forKey:@"NSUnbufferedIO"];
[task setEnvironment:environment];

So should this take care of any buffering issues by the c program?


No. This might work if it was a Foundation-based ObjC program, but it won't change the behaviour of the ordinary C runtime library. The program you are trying to run would have to set its output to unbuffered (see the message Sherm Pendley sent regarding this).


As I said above, one possible workaround is to close the program's input pipe.

Kind regards,

Alastair.

--
http://www.alastairs-place.net



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Debugging Stdout (From: Ronnie O <email@hidden>)
 >Re: Debugging Stdout (From: Frode <email@hidden>)
 >Re: Debugging Stdout (From: Alastair Houghton <email@hidden>)

  • Prev by Date: Re: SenTestingKit and debugging UnitTests
  • Next by Date: Re: Optimizing PDFKit
  • Previous by thread: Re: Debugging Stdout
  • Next by thread: Re: Debugging Stdout
  • Index(es):
    • Date
    • Thread