0

When I execute an exe file (PVFProject15.exe), it reads the data from an input file (inputFile.txt) and print the results in another file (outputFile.txt). The exe file works well when I double click it; It opens the console window which stays opened until the output file is created. However, when I run (PVFProject15.exe) from c#, the console window opens and closes very quickly and the output file is never created.

I would really appreciate your help since I have been working to fix this for a whole day and never found the answer. Here is my code below.

private void button1_Click(object sender, EventArgs e)

{
        Process runFortran = new Process();
        try
        {
            runFortran.StartInfo.FileName = "C:\\temp\\trial\\PVFProject15.exe";
            runFortran.Start();
            runFortran.WaitForExit(); 
        }
        catch (Exception exc)
        {
            MessageBox.Show(exc.Message);
        }
    }

Thank you in advance.

Safaa

2
  • I've tried your code with notepad, and other console application's I've created, and it seems to work fine. Do you have the code for the PVFProject15.exe? Commented Jul 14, 2011 at 18:42
  • 2
    You didn't set StartInfo.WorkingDirectory to @"c:\temp\trial". Lots of poorly written programs cannot survive that. Commented Jul 14, 2011 at 19:17

3 Answers 3

1

Probably PVFProject15.exe needs current directory to be set to C:\temp\trial

Sign up to request clarification or add additional context in comments.

Comments

0

If PVFProject15.exe writes to file using relative path, look for outputFile.txt in directory from which you start your main program-bootstrapper.

Comments

0

I also meet with same problem, when I try start some .exe and .hta from my C# based software. I start to looking for solution and answer of Mike Mozhaev get to me right direction. In your code you need to use: StartInfo.WorkingDirectory = Convert.ToString( System.IO.Directory.GetParent(appPath));

So code have to be like this:

 if (File.Exists(appPath))
                {
                    Process runProcess = new Process();
                    runProcess.StartInfo.WorkingDirectory = Convert.ToString( System.IO.Directory.GetParent(appPath));
                    runProcess.StartInfo.UseShellExecute= true;
                    runProcess.StartInfo.FileName = appPath;
                    runProcess.Start();

                }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.