服务器语言执行shell 输出同步,该如何处理
服务器语言执行shell 输出同步
想用服务端语言执行shell脚本,php,jsp,node之类的,一般情况下这些语言获取shell输出结果都是整个shell执行完才能输出。
现在想做的是shell的输出同步,例如执行find / -name "*.conf" 后shell输出一行,node也能马上输出一行
------解决思路----------------------
你可以将 执行结果的STDOUT_FILENO重定向(dup2)到你需要读取的文件描述符上。
------解决思路----------------------
I don't think the it will work.
She'll works that way because the FILE stream stdout is line buffered since it is with terminal. Simply cloning file no. through dup2 will not change the behavior of buffering on the stream.
想用服务端语言执行shell脚本,php,jsp,node之类的,一般情况下这些语言获取shell输出结果都是整个shell执行完才能输出。
现在想做的是shell的输出同步,例如执行find / -name "*.conf" 后shell输出一行,node也能马上输出一行
------解决思路----------------------
你可以将 执行结果的STDOUT_FILENO重定向(dup2)到你需要读取的文件描述符上。
------解决思路----------------------
I don't think the it will work.
She'll works that way because the FILE stream stdout is line buffered since it is with terminal. Simply cloning file no. through dup2 will not change the behavior of buffering on the stream.