On 11/17/2017 01:35 PM, Peter wrote:
> Add some console.log lines to your done and fail functions and before
> your "//  Set html paragragh to insts". It might help you get a better
> idea of what is happening.
>
> with the .done call you are providing a callback that gets called when
> the spawn command finishes. At that point you now have the result and
> you can do what you want with it.
>
> So if your goal here is to run that command and then write it to html
> that needs to happen inside the done callback.
Uggggh, of course.  It was working earlier because I was actually
updating a HTML from the "done" function, but then I tried to move that
result output to a drop down list.  However, I was doing it from outside
of the done callback function.

Thank you very much for clarifying the behavior, and immediately
identifying my misunderstanding of how the done function worked.

Mark
>
> cockpit.spawn(['ls', '/tmp'], { superuser: true})
>     .done(function(data) {
>         // use data to update html
>     }).fail(function(error){
>         // write a failure message to html
>     });
>
>
> On 11/17/2017 10:24 AM, Mark Reynolds wrote:
>>
>>
>> On 11/17/2017 12:50 PM, Peter wrote:
>>> cockpit.spawn returns a promise. It's asynchronous. get_insts will
>>> return before the callbacks that change the value of insts get run.
>>> You need to rethink what you trying to do here and base your code off
>>> of events or callbacks.
>> But I thought the done() method was supposed to wait?  Okay... So please
>> tell me how do I get cockpit to run a os command, and get the
>> results(stdout) from that command?
>>
>> What is weird is that cockpit.spawn().done() is working in other JS
>> functions I have, except this one.  Very odd...  Still trying to see
>> what I changed that broke things because it was working fine a few hours
>> ago...
>>
>>>
>>>
>>> On 11/17/2017 09:40 AM, Mark Reynolds wrote:
>>>> Okay I'm really stumped because this was just working, but
>>>> cockpit.spawn
>>>> seems to be misbehaving
>>>>
>>>> Here is my js:
>>>>
>>>> function get_insts() {
>>>>       var insts = ["None"];
>>>>
>>>>       cockpit.spawn(['ls', '/tmp'], { superuser: true
>>>> }).done(function(data) {
>>>>           insts= ["okay we actually got here"];
>>>>       }).fail(function(error){
>>>>           insts = ["FAIL"];
>>>>       });
>>>>       //  Set html paragragh to insts
>>>>       ...
>>>> }
>>>>
>>>> $(window.document).ready(function() {
>>>>       get_insts();
>>>>       $("body").show();
>>>> });
>>>>
>>>>
>>>>
>>>> "insts" is always set to "None".  Debugging shows odd behavior. 
>>>> When I
>>>> refresh the page cockpit.spawn just doesn't do anything.
>>>>
>>>> cockpit.js
>>>>
>>>> 1832  function(e ,n)   <=  n is the correct list of arguments
>>>>
>>>> But it does not execute function, then it skips to
>>>>
>>>> 1842 u.close = function(e) {
>>>>
>>>> It does not execute function, then it skips to
>>>>
>>>> 1847 returns u
>>>>
>>>> We don't fail, and we don't succeed, and my js function completes.
>>>> Then... my js function get_insts() gets called again automatically
>>>> (not
>>>> sure how its getting called twice from the page reload), and it does
>>>> appear to succeed the second time, data has expected values, but
>>>> somehow
>>>> after we get the data the debugger stops in a cockpit function listed
>>>> below.  It loops a few times in the cockpit function, then my js
>>>> function, get_insts(), just aborts and disappears silently even though
>>>> things seemed to working correctly on the second pass.
>>>>
>>>> cockpit-ws-151-2.fc26
>>>>
>>>> cockpit.js:867
>>>>
>>>>           function P(e) {
>>>>               var n, t, r;
>>>>               r = e.pending;
>>>>               e.process_scheduled = false;
>>>>               e.pending = undefined;
>>>>               for (var o = 0, a = r.length; o < a; ++o) {
>>>>                   e.pur = true;
>>>>                   t = r[o][0];
>>>>                   n = r[o][e.status];
>>>>                   if (i(n)) {
>>>>                       t.resolve(n.apply(e.promise, e.values));     
>>>> <--
>>>> debugger stops here, then its loops and moves on
>>>>                   } else if (e.status === 1) {
>>>>                       t.resolve.apply(t.resolve, e.values);
>>>>                   } else {
>>>>                       t.reject.apply(t.reject, e.values);
>>>>                   }
>>>>               }
>>>>           }
>>>>
>>>>
>>>> I don't know what to do next, this is very odd behavior.  Especially
>>>> since it worked earlier today.   I even rebooted my laptop :-( I tried
>>>> different and simple commands to send to cockpit.spawn, but it doesn't
>>>> change this behavior.
>>>>
>>>> Anything else I should be looking at?
>>>>
>>>> Thanks,
>>>> Mark
>>>> _______________________________________________
>>>> cockpit-devel mailing list -- [email protected]
>>>> To unsubscribe send an email to
>>>> [email protected]
>>>>
>>>
>>>
>>>
>>
>
_______________________________________________
cockpit-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to