On Thursday, August 11, 2016 at 3:08:01 AM UTC+3, Ramel Eshed wrote:
> On Thursday, August 11, 2016 at 2:19:38 AM UTC+3, Tony Mechelynck wrote:
> > There are other factors which are right there in the help:
> > - job_start() returns a Job object and doesn't wait for the job to finish
> > - system() waits for the external command to finish and returns its
> > full stdout output as a string.
> > 
> > I don't know Vim job control really well, but I seem to understand
> > that in order to compare system() timing and job control timing you
> > would have to set up callbacks to gather any output from the channel,
> > and a callback to be called when the job ends (it may still write to
> > stdout after it exits), and measure the time from just before
> > job_start() to just after making sure that all output has been
> > collected and that the job has ended.
> > 
> > You might even, for testing purposes, try to write a System() user
> > function to invoke the argument as a job and return its output as a
> > string, with the disadvantage that you would completely lose job
> > control asynchronism. But it would allow you a better comparison,
> > namely between old-fashioned system() and this new job-control-based
> > System().
> > 
> > Best regards,
> > Tony.
> 
> That's exactly what I've did:
> 
> func! Job()
>     let s:rt = reltime()
>     let g:output = []
>     let g:job = job_start(['/bin/sh', '-c', 'cat ' . expand('%')], {'out_cb': 
> function('s:out_cb'), 'close_cb': function('s:close_cb')})
> endfunc
> 
> func! s:out_cb(channel, msg)
>     call add(g:output, a:msg)
> endfunc
> 
> func! s:close_cb(channel)
>     echo reltimestr(reltime(s:rt))
>     "echo g:output
> endfunc
> 
> " compare with:
> 
> func! System()
>     let s:rt = reltime()
>     let g:output = systemlist('cat ' . expand('%'))
>     echo reltimestr(reltime(s:rt))
> endfunc
> 
> """""""""""""
> I checked it now on my Ubuntu at home - I still see the difference but now 
> both are much faster so even the system() delay is not noticeable. Any idea 
> what could cause the delay on my RHEL?
> 
> BTW, if I remove the comment from the 'echo g:output' line in close_cb() the 
> message is not displayed (actually, it depends on which command is running. 
> for the 'cat' command above -there is no message).

Hi Bram,

Is it possible to make system() work the same way job_start (with a shell) does?
As I mentioned, I get a noticeable delay with system() which I don't get when 
using job_start(['/bin/sh'...).

Thanks,
Ramel

-- 
-- 
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