comparison runtime/doc/channel.txt @ 10244:876fbdd84e52

commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca Author: Bram Moolenaar <Bram@vim.org> Date: Sat Oct 1 14:47:05 2016 +0200 Updated runtime files.
author Christian Brabandt <cb@256bit.org>
date Sat, 01 Oct 2016 15:00:04 +0200
parents 584c835a2de1
children 169a62d5bcb9
comparison
equal deleted inserted replaced
10243:fe057ff11e5f 10244:876fbdd84e52
1 *channel.txt* For Vim version 8.0. Last change: 2016 Sep 20 1 *channel.txt* For Vim version 8.0. Last change: 2016 Sep 29
2 2
3 3
4 VIM REFERENCE MANUAL by Bram Moolenaar 4 VIM REFERENCE MANUAL by Bram Moolenaar
5 5
6 6
463 func MyHandler(channel, msg) 463 func MyHandler(channel, msg)
464 464
465 Without the handler you need to read the output with |ch_read()| or 465 Without the handler you need to read the output with |ch_read()| or
466 |ch_readraw()|. You can do this in the close callback, see |read-in-close-cb|. 466 |ch_readraw()|. You can do this in the close callback, see |read-in-close-cb|.
467 467
468 Note that if the job exits before you read the output, the output may be lost.
469 This depends on the system (on Unix this happens because closing the write end
470 of a pipe causes the read end to get EOF). To avoid this make the job sleep
471 for a short while before it exits.
472
468 The handler defined for "out_cb" will not receive stderr. If you want to 473 The handler defined for "out_cb" will not receive stderr. If you want to
469 handle that separately, add an "err_cb" handler: > 474 handle that separately, add an "err_cb" handler: >
470 let job = job_start(command, {"out_cb": "MyHandler", 475 let job = job_start(command, {"out_cb": "MyHandler",
471 \ "err_cb": "ErrHandler"}) 476 \ "err_cb": "ErrHandler"})
472 477
514 *read-in-close-cb* 519 *read-in-close-cb*
515 If the job can take some time and you don't need intermediate results, you can 520 If the job can take some time and you don't need intermediate results, you can
516 add a close callback and read the output there: > 521 add a close callback and read the output there: >
517 522
518 func! CloseHandler(channel) 523 func! CloseHandler(channel)
519 while ch_status(a:channel) == 'buffered' 524 while ch_status(a:channel, {'part': 'out'}) == 'buffered'
520 echomsg ch_read(a:channel) 525 echomsg ch_read(a:channel)
521 endwhile 526 endwhile
522 endfunc 527 endfunc
523 let job = job_start(command, {'close_cb': 'CloseHandler'}) 528 let job = job_start(command, {'close_cb': 'CloseHandler'})
524 529