> On 25 Apr 2016, at 10:06 pm, Bram Moolenaar <b...@moolenaar.net> wrote:
> The exit callback is only invoked once Vim detects the job is gone.  By
> then it's too late to read the output.  This is documented.  
> 
> There is also the close_cb for the channel, which gets called much
> sooner than the exit_cb.  Actually, it's called before the out_cb
> function, should probably change that.

Good to know, thanks.

> Perhaps, when there is a close_cb, the DETACH message should not be
> added.  That simplifies how it works.

If I read a job's stdout with an "out_cb" handler, and the output has multiple 
lines, what's the right way to know that the job has finished and no more 
output is coming?

In NL mode I suppose I could keep accumulating the output via the handler, one 
line at a time, stopping when the message is "DETACH".

In RAW mode I get all the output at once – is that the recommended way for my 
situation?

Initially I tried to start a job without any handlers because I read this in 
the documentation:

    Without the handler you need to read the output with ch_read() or 
ch_readraw().

Where would such a call go if it's not in a callback?

When I start two jobs with similar commands I only seem to get the output for 
the second.  Here's a demo:

$ cat demo.vim
call ch_logfile('channellog', 'w')

function! OutHandler(channel, msg)
  echom 'OutHandler'
  echom '    '.a:channel
  echom '    '.a:msg
endfunction

let job = job_start('ls',    {'mode': 'raw', 'out_cb': 'OutHandler'})
let job = job_start('ls -l', {'mode': 'raw', 'out_cb': 'OutHandler'})

$ vim -u NONE -N -S demo.vim

$ cat channellog 
==== start log session ====
  0.000033 : Starting job: ls
  0.000071 on 0: Created channel
  0.000543 : Starting job: ls  -l
  0.000599 on 1: Created channel
  0.001033 : looking for messages on channels
  0.003977 RECV on 0: 'andanother
channellog
demo.vim
otherfile
somefile
'
  0.003998 on 0: Closing channel
  0.004103 on 0: Clearing channel
  0.004113 on 0: Freeing channel
  0.004120 : looking for messages on channels
  0.005818 RECV on 1: 'total 16
-rw-r--r--  1 andy  staff    0 26 Apr 11:16 andanother
-rw-r--r--  1 andy  staff  204 26 Apr 11:17 channellog
-rw-r--r--  1 andy  staff  289 26 Apr 11:17 demo.vim
-rw-r--r--  1 andy  staff    0 26 Apr 11:16 otherfile
-rw-r--r--  1 andy  staff    0 26 Apr 11:16 somefile
'
  0.005835 on 1: Invoking channel callback OutHandler
  0.006085 ERR on 1: channel_select_check(): Cannot read from channel
  0.006097 PUT on 1: 'DETACH
'
  0.006100 on 1: Closing channel
  0.006170 : looking for messages on channels
  0.006177 on 1: Invoking channel callback OutHandler
  1.338691 : looking for messages on channels

You can see the OutHandler callback is not invoked on channel 0.

However if the second job's command is, say, 'cal' instead of 'ls -l', the 
callback is invoked for both jobs as expected.

I also noticed that the job's command in sensitive to whitespace.  A job 
command of ' ls' instead of 'ls' produces no output:

$ cat channellog 
==== start log session ====
  0.000032 : Starting job:   ls
  0.000070 on 0: Created channel
  0.000600 : looking for messages on channels
  0.001676 ERR on 0: channel_select_check(): Cannot read from channel
  0.001685 PUT on 0: 'DETACH
'
  0.001686 on 0: Closing channel
  0.001715 : looking for messages on channels
  0.001721 on 0: Invoking channel callback OutHandler
  0.001829 : looking for messages on channels

I would expect leading / trailing whitespace not to affect anything.

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui