Re: [code] [textadept] output from spawn on Windows?

From: Mitchell <m.att.foicica.com>
Date: Wed, 11 Feb 2015 12:11:11 -0500 (EST)

On Tue, 10 Feb 2015, Mateusz Czaplinski wrote:

> On Tue, Feb 10, 2015 at 10:41 PM, Mateusz Czaplinski <czapkofan.att.gmail.com>
> wrote:
>
>>
>>
>> On Tue, Feb 10, 2015 at 2:15 AM, Mitchell <m.att.foicica.com> wrote:
>>
>>> Hi Mateusz,
>>>
>>> On Tue, 10 Feb 2015, Mateusz Czaplinski wrote:
>>>
>>> pp=spawn('git --version',_USERHOME,ui.print,ui.print,ui.print) pp:wait()
>>>> ui.print('hi')
>>>>
>>>> and the output I get is:
>>>>
>>>> hi
>>>> git version 1.9.4.msysgit.2
>>>>
>>>> 0
>>>>
>>>> so, the callbacks are apparently still called async, long after the
>>>> :wait()
>>>> has finished. So that's probably why I wasn't able to capture anything?
>>>> That doesn't seem to give me much hope as to processing the command's
>>>> output and doing something useful afterwards in a synchronous way...
>>>>
>>>
>>> Calling `pp:wait()` blocks Lua, preventing async callbacks from running
>>> until after the current Lua function (which in your case includes printing
>>> 'hi' first). If you want to synchronously read a process' output, use
>>> `pp:read()` without `pp:wait()`.
>>>
>>> The simplest thing I can do is from the command entry:
>>>
>>> =spawn('ruby -v'):read('*a')
>>>
>>> This works just fine.
>>>
>>
>> Ok, for a simple command, read() worked, thanks. But then, via read() I
>> can't get the STDERR output, unfortunately, right? Nor the exit code of the
>> process?
>>
>
> Hmm, so if I understand correctly, I could still do something afterwards by
> adding any subsequent logic to the callbacks? So that, e.g. if I wanted to
> call a few commands in sequence, each one would have the remaining ones as
> nested callbacks? Something like in node.js reportedly?

I don't know the answer to that. All I can tell you is that as long as a
process is producing standard output or standard error, any callbacks
passed to spawn will be called[1]. When the process finishes, its exit
callback is called. If you are doing things in Lua while the process
finishes, there's no guarantee any callbacks will be called (as I
understand it).

Cheers,
Mitchell

[1]: As long as any calls to `proc:read()` read all available output.

-- 
You are subscribed to code.att.foicica.com.
To change subscription settings, send an e-mail to code+help.att.foicica.com.
To unsubscribe, send an e-mail to code+unsubscribe.att.foicica.com.
Received on Wed 11 Feb 2015 - 12:11:11 EST

This archive was generated by hypermail 2.2.0 : Thu 12 Feb 2015 - 06:47:39 EST