Thanks Ken,

On Jan 29, 2011, at 10:36 AM, Robert DuToit wrote:

> Thanks Ken,
> On Jan 29, 2011, at 9:29 AM, Ken Thomases wrote:
> 
>> 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.
> 


I have been googling around and not sure how to do this - is it with NSData or 
NSStream perhaps?

Cheers and thanks for all,

Rob



> I have been googling around and not sure how to do this - is it with NSData 
> or NSStream perhaps?
> 
> Cheers and thanks for all,
> 
> Rob
> 
> 
>> 
>> 
>>>> 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 (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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Reply via email to