Send a EOF in a pipe without closing it

若如初见. 提交于 2019-12-10 14:59:56

问题


I am writing an app which uses GnuPlot for ploting data. Instead of using text format to comunicate both programs though a pipe (it is slow because of the vprintf() and the big amount of data being passed) I decided to use "binary" format.

The problem is that in binary format GnuPlot expects a EOF (Ctrl+D) to end the transmission and plot the data. This is easy in UNIX console mode. Just pressing Ctrl+D will end the data input, plot the data AND mantain the console open waiting for more commands.

But in my C++ app the only way to send a EOF is to close the pipe. This causes the gnuplot process to die and does not show the plot to the screen.

¿Is there some trick to send a EOF to a pipe? ¿How does the UNIX terminal manage to send a EOF without closing its pipe with the running process?

PD: I can't close and reopen GnuPlot with "-persist", because that generates a NEW plot instead of updating the old plot (it is a real time system so it generates near ~inf plot windows).


回答1:


I don't think what you want to do will work. See for example:

http://www.velocityreviews.com/forums/t365339-write-eof-without-closing.html

Can we write an EOF character ourselves?

Basically EOF is no character per se. It's the end of the file.

So as I noted in the comment above I suggest you try using a library which connects you directly to gnuplot. Then you should be able to control it such that your desired behaviour is achieved (most likely using something like replot).



来源:https://stackoverflow.com/questions/9633577/send-a-eof-in-a-pipe-without-closing-it

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!