skywind3000/asyncrun.vim

unknown bug (duplicate output maybe)

Closed this issue · 1 comments

yaoyhu commented

I am writing a simple code about creating process, the output in terminal like below:

➜ tmp gcc p2.c -o p2; ./p2

pid:80230
child:80231
parent of 80231 (wc = 80231) (pid = 80230)

But with :AsyncRun gcc p2.c -o p2; ./p2:

  5 || [gcc p2.c; ./a.out]                                                                                                                                                                                           
  4 || pid:78520                                                                                                                                                                                                     
  3 || child:78526                                                                                                                                                                                                   
  2 || pid:78520    ----------> what is this????                                                                                                                                                                                              
  1 || parent of 78526 (wc = 78526) (pid = 78520)                                                                                                                                                                    
6   || [Finished in 0 seconds] 

image

It is not a tty, in C standard library, if the process is running in a pipe, the stdout will be buffered until you call fflush or process exits.

So, the printf in line 7 is buffered with the later printf in line 11 or line 15 and the actual display happens in returns.

Since there is a fork, you will see two pid:xxxx.

To eliminate this, you should add a fflush(stdout); after line 7, this will ensure to display all the outputs of previous printfs.