Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Calling UNIX command hungs widget



Thanks.
That workaround works.
But in the Dashboard Reference revision 2006-05-23 the synchronous execution is still available.
Obviously it should work the synchronous way, but it doesn't.
I've attached a testWidget so everyone can try for himself.
It has the synchronous and the asynchronous methods included.
test1 reads a 1kb file synchrounous.
test50 reads a 50kb file synchronous but it fails. "cat" hungs and it's task has to be killed manually.
workaround1 and workaround50 do it the asynchronous way.


I'd like to prefer the synchronous execution where it is possible and the asynchronous where it is needed.
Writing a function that uses such a synchronous way is much easier to write.
Making it asynchronous only messes up the code.


I'm using an iMac Core Duo with Mac OS X 10.4.7 (8J2135).

Regards

Michael


Attachment: TestWidget.wdgt.zip
Description: Zip archive



Am 25.08.2006 um 16:36 schrieb Johnny Storm:

It hung because you are using synchronous calls not asynchronous, Apple doesn't allow synchronous calls in widgets anymore

what you need to do is this:

widget.system( "/path/to/command", processOutput );

function processOutput(result) {
    if(result.outputString) {
          output = result.outputString;
    }
}

one of the cool features of asynchronous commands is you can dynamically assign functions like so:

var cmd = widget.system( "/path/to/command", function(output) { processOutput(output); } );

the latter allows you to run actions that are in a loop or require dynamic variables that are not supported outside of the loop.

Hope that helps
On 8/25/06, Michael Kwasnicki <email@hidden> wrote:Hi,

I'm using a commandline tool to pass data to my widget this way.

var output = widget.system( "/path/to/command", null ).outputString;

I wondered why my widget hung as the passed data grew.
The data that is passed to the stdout by the command is easily
greater than 40kb.
First I thought there is a memory limit for variables in JavaScript.
But a shorter output concatenated with the same output ten times
produced far more than 40kb in that variable.
Then I noticed something odd. I was not the widget that hung. It was
the command.
Killing the command in the Activity Monitor revived the widget.
Since the command does not hung in the Terminal I think there is some
oddity in the widget.system() thing.
It even hungs on "cat longtext.txt" if longtext.txt is long enough.
That is why I'm absolutely sure that it is not the fault of my
commandline tool.
Please can someone verify that and tell me what to do?

Thanks,

Michael
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Dashboard-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/dashboard-dev/email@hidden

This email sent to email@hidden

References: 
 >Calling UNIX command hungs widget (From: Michael Kwasnicki <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.