|
From: Frank S. <der...@gm...> - 2012-05-26 11:39:53
|
Hello, everybody!
I am writing a C# program, that uses gnuplot via piping. See a minimal
example in the attachment. (You probably have to fit the gnuplot path to
your installation or use an environment variable just like me.)
This console program calls gnuplot und plots the function x+y. But after
that, gnuplot is not closed correctly. If you close the wxt window, the
command
gpProc.WaitForExit();
still blocks, although
bind Close "exit gnuplot"
is set in gnuplot.
But in fact, I don’t care about this. The critical point is: If you hit
a key (e. g. try to close the window with q or Alt + F4), gnuplot seems
to hang.
I am using:
– Windows XP 32bit
– gnuplot 4.6.0 (latest released version; same problem with 4.4.4)
– Windows Visual C# 2010 (other compilers are not an option and I didn’t
try others yet)
– .Net-Framework 4.0 (same problem with 3.5 and probably others)
This problem does not occur under linux. I am not sure, whether it is
caused by windows or by gnuplot. In any case gnuplot can be closed
correctly by uncommenting
gpcommands.WriteLine("exit");
Hope you can help or give an advice.
Thanks!
Greetings
Frank
|
|
From: Hans-Bernhard B. <HBB...@t-...> - 2012-05-27 13:07:18
|
On 26.05.2012 13:39, Frank Stähr wrote: > Hello, everybody! > > I am writing a C# program, that uses gnuplot via piping. See a minimal > example in the attachment. (You probably have to fit the gnuplot path to > your installation or use an environment variable just like me.) No attachment --- might have been stripped by the mailing list processor. > – Windows Visual C# 2010 (other compilers are not an option and I didn’t > try others yet) > – .Net-Framework 4.0 (same problem with 3.5 and probably others) > > This problem does not occur under linux. I do wonder: since you are considering other platforms than MS, why on earth would you be programming in C#? |
|
From: Frank S. <der...@gm...> - 2012-05-29 14:57:29
|
Hi and sorry for my late answer. Am Sonntag, den 27.05.2012, 15:07 +0200 schrieb Hans-Bernhard Bröker: > No attachment --- might have been stripped by the mailing list processor. Yes! At least I didn’t forget it. This mail should have an attachment, but for sure here’s the source code: ========== using System.Diagnostics; using System.IO; class Program { static void Main(string[] args) { ProcessStartInfo processStartInfo = new ProcessStartInfo(@"gnuplot"); //new ProcessStartInfo(@"C:\Programme\gp460win32\binary\gnuplot.exe"); processStartInfo.UseShellExecute = false; processStartInfo.RedirectStandardInput = true; Process gpProc = new Process(); gpProc.StartInfo = processStartInfo; gpProc.Start(); StreamWriter gpcommands = gpProc.StandardInput; gpcommands.WriteLine("splot x+y"); gpcommands.WriteLine("bind Close \"exit gnuplot\""); //gpcommands.WriteLine("exit"); gpProc.WaitForExit(); } } ======== > > – Windows Visual C# 2010 (other compilers are not an option and I didn’t > > try others yet) Now I know that the Mono compiler has the same problem. > > – .Net-Framework 4.0 (same problem with 3.5 and probably others) > > > > This problem does not occur under linux. > > I do wonder: since you are considering other platforms than MS, why on > earth would you be programming in C#? The thing with linux is just a hint for you. I have to work under MS at work. And in this special case, I also do not have the choice to use another language than C#. |
|
From: Morten L. <mor...@no...> - 2012-06-11 11:20:13
|
> Yes! At least I didn’t forget it. This mail should have an attachment, > but for sure here’s the source code: > ========== > using System.Diagnostics; > using System.IO; > > class Program > { > static void Main(string[] args) > { > ProcessStartInfo processStartInfo = > new ProcessStartInfo(@"gnuplot"); > //new ProcessStartInfo(@"C:\Programme\gp460win32\binary\gnuplot.exe"); > processStartInfo.UseShellExecute = false; > processStartInfo.RedirectStandardInput = true; > > Process gpProc = new Process(); > gpProc.StartInfo = processStartInfo; > gpProc.Start(); > StreamWriter gpcommands = gpProc.StandardInput; > gpcommands.WriteLine("splot x+y"); > gpcommands.WriteLine("bind Close \"exit gnuplot\""); > //gpcommands.WriteLine("exit"); > gpProc.WaitForExit(); > } > } > ======== > I have just tried this code using gnuplot 4.6 in a .Net 4.0 project on Windows 7 machine, and I was not able to reproduce the problem. After the window was closed, execution returned to the main method. No hanging on WaitForExit. /Morten |
|
From: Hans-Bernhard B. <HBB...@t-...> - 2012-05-29 17:28:34
|
On 29.05.2012 16:56, Frank Stähr wrote:
> Am Sonntag, den 27.05.2012, 15:07 +0200 schrieb Hans-Bernhard Bröker:
>> No attachment --- might have been stripped by the mailing list processor.
>
> Yes! At least I didn’t forget it. This mail should have an attachment,
Nope. Odds are our Mailman is configured to reject attachments to this
list.
[...]
> gpcommands.WriteLine("splot x+y");
> gpcommands.WriteLine("bind Close \"exit gnuplot\"");
I'll venture a wild guess here: you might fare better with these two
lines in the opposite order. Generally speaking, it's usually best for
the plot or splot command, if there's only one, to be the last in any
script.
|
|
From: Frank S. <der...@gm...> - 2012-06-01 15:41:32
|
Am Dienstag, den 29.05.2012, 19:28 +0200 schrieb Hans-Bernhard Bröker:
> > gpcommands.WriteLine("splot x+y");
> > gpcommands.WriteLine("bind Close \"exit gnuplot\"");
>
> I'll venture a wild guess here: you might fare better with these two
> lines in the opposite order.
No, that doesn’t make a difference in this case. Even if you remove the
bind close line, the plot window freezes after hitting a key.
|
|
From: Tait <gnu...@t4...> - 2012-06-01 19:31:49
|
> > > gpcommands.WriteLine("splot x+y");
> > > gpcommands.WriteLine("bind Close \"exit gnuplot\"");
Does this have anything to do with C# at all? Even interactively (4.6p0),
"bind Close exit" does not seem to work. Other things, like "bind close
print 'test'" do seem to work, so the binding happens but simply doesn't
work for quit/exit.
(Sorry if you get this multiple times; I accidentally sent it to the
wrong list.)
|
|
From: Frank S. <der...@gm...> - 2012-06-06 15:38:59
|
Am Freitag, den 01.06.2012, 12:31 -0700 schrieb Tait:
> > > > gpcommands.WriteLine("splot x+y");
> > > > gpcommands.WriteLine("bind Close \"exit gnuplot\"");
>
> Does this have anything to do with C# at all? Even interactively (4.6p0),
> "bind Close exit" does not seem to work.
No, everything is ok in interactive mode. At least the plot window does
not freeze by hitting q. (I think you have to use bind Close "exit
gnuplot" instead.)
It works with linux, but with the same compiler for windows not. I would
guess the problem is MS or gnuplot.
Of course, the behavior of a pipe via C++ or C would be very
interesting.
|
|
From: Hans-Bernhard B. <HBB...@t-...> - 2012-06-06 20:54:44
|
On 06.06.2012 17:37, Frank Stähr wrote: > It works with linux, but with the same compiler for windows not. I would > guess the problem is MS or gnuplot. It could just as easily be caused by the choice of terminal driver --- GUI subsystems like X11, native Win32, wxt and qt behave way differently under the hood. gnuplot tries rather hard to hide that fact behind the curtain, but it's still there. |
|
From: Tait <gnu...@t4...> - 2012-06-08 00:39:10
|
> > > > > gpcommands.WriteLine("splot x+y");
> > > > > gpcommands.WriteLine("bind Close \"exit gnuplot\"");
> >
> > Does this have anything to do with C# at all? Even interactively (4.6p0),
> > "bind Close exit" does not seem to work.
>
> No, everything is ok in interactive mode. At least the plot window does
> not freeze by hitting q. (I think you have to use bind Close "exit
> gnuplot" instead.)
> It works with linux, but with the same compiler for windows not. I would
> guess the problem is MS or gnuplot.
>
> Of course, the behavior of a pipe via C++ or C would be very
> interesting.
Okay, adding the gnuplot to "bind Close 'exit gnuplot'" makes it work
as expected.
In interactive mode, it works for me, as you described. I don't have a C#
compiler, but from gnuplot's point of view, there should be no difference
between what you're doing in C# to write to gnuplot's STDIN and:
echo bind Close 'exit gnuplot'; splot x+y; pause -1 | gnuplot.exe
And that works just fine for me. I can close the plot window with either
q or alt+F4 and I am returned to the command prompt.
If I add a print, e.g.:
echo bind Close 'exit gnuplot'; splot x+y; pause -1; print 'got this far' | gnuplot.exe
the print never happens, suggesting the binding is indeed working.
Even adding a "set terminal windows" does not change the behavior
(with alt+F4 since the windows terminal doesn't accept q to close).
I'm using a 64-bit OS (Windows 2003). I wouldn't expect that to matter,
as gnuplot is a 32-bit app regardless. I cannot duplicate what you're
seeing.
|
|
From: Frank S. <der...@gm...> - 2012-06-09 08:11:32
|
Am Donnerstag, den 07.06.2012, 17:38 -0700 schrieb Tait: > In interactive mode, it works for me, as you described. I don't have a C# > compiler, but from gnuplot's point of view, there should be no difference > between what you're doing in C# to write to gnuplot's STDIN and: > echo bind Close 'exit gnuplot'; splot x+y; pause -1 | gnuplot.exe Exactly, but there is! I have hoped, that someone of you perhaps has already worked with a C#-gnuplot-pipe, but it doesn’t seem so. > And that works just fine for me. For me, too. > Even adding a "set terminal windows" does not change the behavior > (with alt+F4 since the windows terminal doesn't accept q to close). Yes, neither for C# nor interactively. > I'm using a 64-bit OS (Windows 2003). I wouldn't expect that to matter, > as gnuplot is a 32-bit app regardless. I cannot duplicate what you're > seeing. Please try it. Just install the mono compiler und run my example. You can find it here: <http://download.mono-project.com/archive/2.10.8/windows-installer/1/mono-2.10.8-gtksharp-2.12.11-win32-1.exe> Compile the source file with (depending on your installation): C:\Programs\Mono-2.10.8\bin\mcs.bat Program.cs Unfortunately you have Windows 2003 instead of XP … let’s be optimistic. |