Hi, From: ptkwt / shell1.aracnet.com (Phil Tomson) Subject: Re: tkgnuplot problem: fork() on win (popen3 for windows?) Date: Tue, 28 Jan 2003 14:40:20 +0900 Message-ID: <b152lh0kc4 / enews2.newsguy.com> > Didn't someone recently announce that they implemented popen3 for Windows? Thank you for your information. Well, Ralf, could you try the following patch? Because I have no environment to test it. --- ../TkGnuplot.old/gnuplot.rb Thu Oct 3 10:52:39 2002 +++ ./gnuplot.rb Wed Jan 29 11:57:49 2003 @@ -2,12 +2,50 @@ # # gnuplot.rb : create and communicate with Gnuplot process # by Hidetoshi NAGAI <nagai / ai.kyutech.ac.jp> -# Time-stamp: "2002-10-03 10:52:39 nagai" +# Time-stamp: "03/01/29 11:57:49 nagai" # require 'thread' class GnuplotProcess + def _win32_open_process(*cmd) + require 'win32_popen' + + IO.win32_popen4(cmd.join(' ')) + end + + def _open_process(*cmd) + to_cmd_r, to_cmd_w = IO.pipe + from_cmd_r, from_cmd_w = IO.pipe + + # create gnuplot process + begin + Process.waitpid fork { + fork { + to_cmd_w.close + from_cmd_r.close + STDIN.reopen(to_cmd_r) + STDOUT.reopen(from_cmd_w) + STDERR.reopen(from_cmd_w) + STDOUT.sync = true + + exec(*cmd) + } + + exit! + } + + to_cmd_r.close + from_cmd_w.close + to_cmd_w.sync = true + rescue NotImplementedError + to_cmd_w, from_cmd_r = _win32_open_process(*cmd) + end + + [to_cmd_w, from_cmd_r] + end + private :_open_process, :_win32_open_process + def initialize(*args) # head arg == gnuplot command path ? if args[0].kind_of? String @@ -23,32 +61,9 @@ params = {} end - to_cmd_r, to_cmd_w = IO.pipe - from_cmd_r, from_cmd_w = IO.pipe - - # create gnuplot process - Process.waitpid fork { - fork { - to_cmd_w.close - from_cmd_r.close - STDIN.reopen(to_cmd_r) - STDOUT.reopen(from_cmd_w) - STDERR.reopen(from_cmd_w) - STDOUT.sync = true - - opt = [] - params.collect{|key,value| opt << '-' + key.to_s << value.to_s} - exec(gnuplot, *opt) - } - - exit! - } - - to_cmd_r.close - from_cmd_w.close - @to_cmd = to_cmd_w - @from_cmd = from_cmd_r - @to_cmd.sync = true + cmd = [gnuplot] + params.each{|key,value| cmd << '-' + key.to_s << value.to_s} + @to_cmd, @from_cmd = _open_process(*cmd) @mutex = Mutex.new # for Thread-safe @mode = 0 # 0 : no plot, 2 : 2D plot, 3 : 3D plot