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

From: Mitchell <m.att.foicica.com>
Date: Mon, 9 Feb 2015 20:15:58 -0500 (EST)

Hi Mateusz,

On Tue, 10 Feb 2015, Mateusz Czaplinski wrote:

> Hmh, argh, right, `..` not `+`, dumb error... too long without Lua... but,
> that doesn't really solve the rest, unfortunately....
>
> It starts to smell somewhat fishy to me now: I've just tried Ctrl-E with:
>
> 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.

Cheers,
Mitchell

>
> /M.
>
> On Mon, Feb 9, 2015 at 3:26 PM, Mitchell <m.att.foicica.com> wrote:
>
>> Hi Mateusz,
>>
>> On Sat, 7 Feb 2015, Mateusz Czaplinski wrote:
>>
>> Hi,
>>>
>>> I tried to use spawn() on Windows, and retrieve some output from it, but
>>> all seems empty. Is it supposed to work on Windows (7, x64)? Maybe I'm
>>> using it wrong - could you please maybe show me a full command that's
>>> expected to work to capture output? (To be more precise: the command
>>> seemed
>>> to run successfully in itself, only I couldn't capture the output.) I
>>> tried
>>> something like below:
>>> local pout, perr, pcode = '', '', nil
>>> local proc = spawn(my_command, my_workdir,
>>> function(out) pout = pout + out end,
>>> function(out) perr = perr + out end,
>>> function(code) pcode = code end)
>>> local s, errc, err = proc:read '*a'
>>> if s==nil then
>>> ui.print('error: '..errc..' '..err)
>>> end
>>> ui.print('s=', s)
>>> ui.print('pout=', pout)
>>> ui.print('perr=', perr)
>>> ui.print('pcode=', pcode)
>>> In the [Message Buffere] they all show empty, and pcode shows nil.
>>> Also tried to add proc:wait() before or after the read(), but doesn't seem
>>> to help either.
>>>
>>
>> You are using `proc:read()`, so the stdout and stderr callbacks will never
>> populate `pout` and `perr` (it wouldn't work anyway since you should be
>> using the concatenation operator `..` instead of numeric addition `+`). Try
>> using `proc:wait()` without any call to `proc:read()`.
>>
>> I've entered the following command into the command entry and gotten the
>> proper output in the message buffer:
>>
>> spawn('ruby -v', nil, ui.print, ui.print, ui.print)
>>
>> (No `wait()`, `read()`, etc. I just let the asynchronous process do its
>> thing.)
>>
>> Cheers,
>> Mitchell
>> --
>> 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.
>>
>>
>

Mitchell

-- 
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 Mon 09 Feb 2015 - 20:15:58 EST

This archive was generated by hypermail 2.2.0 : Tue 10 Feb 2015 - 06:46:09 EST