Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8756689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:08:11+00:00 2026-06-13T14:08:11+00:00

A mysterious behavior was found in my code. Briefly speaking, the point is the

  • 0

A “mysterious” behavior was found in my code. Briefly speaking, the point is

  • the line that works with a breakpoint does not work without breakpoints
  • it has nothing to do with privileges (unlike a lot of questions about ‘Win32Exception’ do)

A somewhat similar symptom was reported here: MSBuild Script gets "Win32Exception: The system cannot find the File Specified" … in that both have something to do with debugging process. (I am not sure if it has something to do with my problem, though.)

I am writing a code to

  1. produce a histogram in text format
  2. launch ‘gnuplot’ by using ‘System.Diagnostics.Process.Start’ to plot the generated histogram
  3. open the image file generated by gnuplot by also using ‘Process.Start(“generatedPlot.png”).

1,2 seem to be executed successfully, because I get a png image in the working directory.

However, in spite of the existence of the plot image, I get a ‘Win32Exception’ saying “The specified files was not found” when I try to open the file with

void GeneratePlot()
{
  // generate a png image called 'outputPath' with console 'gnuplot.exe'
  MyClass.gnuplot(dataFilePath,outputPath);
  MyClass.OpenFile(outputPath);
}

OpenFile is defined simply as

static void OpenFile(string fileToOpen)
{
  Process.Start(fileToOpen);  // this throws 'Win32Exception'  ...(*)
}

The mysterious thing is here: In order to debug this problem, I put a breaking point at (*). Then the exception is no longer thrown!

(NOTE: Because the plot image is successfully created, you don’t get the exception in the second run with the same ‘fileToOpen’. Therefore, please make sure you delete the generated plot image before debugging.)

I managed to find a way other than placing a breakpoint there, of course. What I did was just separating the execution of MyClass.gnuplot and MyClass.OpenFile:

void GeneratePlot()
{
  // some code
  MyClass.gnuplot(dataFilePath, outputPath);
}

void button1_Click(object sender, EventArgs e)
{
  MyClass.OpenFile(outputPath);
}

After I execute ‘GeneratePlot()’, hit ‘button1’. This time it shows the png image!

Just in case, I write a code like this to create a png plot image: (it works fine alone!)

static void gnuplot(string dataFilePath, string outputPath)
{
  Process p = new Process();
  p.StartInfo.FileName = \\path\\to\\gnuplot.exe;
  p.StartInfo.RedirectStandardInput = true;
  p.StartInfo.WorkingDirectory = Directory.GetWorkingDirectory();
  // some other StartInfo setting
  p.Start();

  // execute gnuplot with the following
  StreamWriter sw = new StreamWriter(p.StandardInput);
  sw.WriteLine("set terminal \"png\"");
  sw.WriteLine("set output " + outputPath);
  sw.WriteLine("plot '{0}'",dataFilePath);
}

I am curious about why this happens. Could you give me advise? Thank you very much in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T14:08:12+00:00Added an answer on June 13, 2026 at 2:08 pm

    There might be a race conditon between the time the file is being created and written by gnuplot and the time that you attempt to open the file in your own process. I’ll bet that when you run this in the debugger, enough time has passed by the time the breakpoint is hit that the gnuplot process has closed the output file.

    To solve this, you can wait some period of time after sending the plot command, or better yet, wait for the gnuplot process to exit.

    static void gnuplot(string dataFilePath, string outputPath)
    {
      Process p = new Process();
      p.StartInfo.FileName = \\path\\to\\gnuplot.exe;
      p.StartInfo.RedirectStandardInput = true;
      p.StartInfo.WorkingDirectory = Directory.GetWorkingDirectory();
      // some other StartInfo setting
      p.Start();
    
      // execute gnuplot with the following
      StreamWriter sw = new StreamWriter(p.StandardInput);
      sw.WriteLine("set terminal \"png\"");
      sw.WriteLine("set output " + outputPath);
      sw.WriteLine("plot '{0}'",dataFilePath);
    
      // ----> wait for gnuplot to exit before returning
      // (presumes that gnuplot exits shortly after executing the plot command)
      p.WaitForExit();
    }
    

    If the p.WaitForExit(); statement doesn’t work (ie, the gnuplot process doesn’t exit after executing the plot command), try Thread.Sleep(TimeSpan.FromSeconds(1.0)); (or some other period of time) instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The AppDomain.TypeResolve is mysterious in my eyes. Can someone provide a sample code that
Today I found a very mysterious bug in the code. I have used the
The following code is not returning None but some mysterious main _.link_list object: class
I've playing around with linux and noticed that for some mysterious reason commands like
I have a problem that appears and disappears for mysterious reasons. A while back
Here's a mysterious python problem: I'm developing a python package that occasionally reports import
I ran into what seemed a mysterious bug this morning that I feel very
XCode works in mysterious ways (at least to me). I simply want to create
I'm having a mysterious bug where a rest call that I've created on my
NSCollectionView remains one of the most mysterious parts of the Cocoa API that I've

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.