• 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: readInBackgroundAndNotify and rsync output
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: readInBackgroundAndNotify and rsync output


  • Subject: Re: readInBackgroundAndNotify and rsync output
  • From: Ken Thomases <email@hidden>
  • Date: Sat, 29 Jan 2011 08:29:33 -0600

On Jan 29, 2011, at 8:01 AM, Robert DuToit wrote:

> On Jan 29, 2011, at 5:15 AM, Ken Thomases wrote:
>
>> You should definitely not be creating subprocesses to run 'tail' or 'ps'.  'tail' is just a file reader, and your app can directly open and read the file.  To monitor whether rsync is still running, you may be able to use the techniques illustrated in these articles:
>
> I know - I didn't see any easy way to directly read in just some last lines of the log as 'tail' does assuming you don't want to read in 1 million lines of a log every fraction of a second and then parse. I'll research this more.

You shouldn't open the file and read from the beginning every time.  Open the file once after rsync creates it, then read some data (perhaps up to the then-current end of file) and parse it, keeping in mind that the final line may be incomplete.  At the next firing of your timer, clear the end-of-file marker and read some more.  Append the new data to whatever partial line was left over from the last time.  Etc.


>> It may also be possible to use a pipe to the rsync process not for communicating its output but just to monitor its lifetime.  If you redirect most of rsync's output to a file (e.g. using the --log-file option), then you can monitor its stdout (and/or stderr) from your app.  When it closes, the process has presumably exited.
>
> I hadn't thought of that - I was redirecting the stdout in the Helper Tool using a timer to poll the log but never thought of the rsync option itself!  I'll have to check this out. That would do away with  the ps call nicely. Isn't the stdout already redirected to the file though via rsync? Maybe the two can coincide.

I wouldn't expect the --log-file option to redirect stdout.  Even if it did, you can (and probably should) capture the rsync stderr via the pipe, and that should only close when the process exits.

> Thanks Ken. This has been an enlightening discussion.

You're welcome.

Cheers,
Ken

_______________________________________________

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: 
 >readInBackgroundAndNotify and rsync output (From: Robert DuToit <email@hidden>)
 >Re: readInBackgroundAndNotify and rsync output (From: Ken Thomases <email@hidden>)
 >Re: readInBackgroundAndNotify and rsync output (From: Robert DuToit <email@hidden>)
 >Re: readInBackgroundAndNotify and rsync output (From: Ken Thomases <email@hidden>)
 >Re: readInBackgroundAndNotify and rsync output (From: Robert DuToit <email@hidden>)

  • Prev by Date: Re: readInBackgroundAndNotify and rsync output
  • Next by Date: (id) issue, passing different types during initWith:(id)type
  • Previous by thread: Re: readInBackgroundAndNotify and rsync output
  • Next by thread: Re: readInBackgroundAndNotify and rsync output
  • Index(es):
    • Date
    • Thread