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 8589773
In Process

The Archive Base Latest Questions

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

I have a class which handles execution of an exe process, which is a

  • 0

I have a class which handles execution of an exe process, which is a console application (written in Fortran!). When running this program, the user must first enter the name of an input file (which must exist in the same location as the exe), and an output file (which does not yet exist, but is produced by the exe.

In my unit tests for the Execute method (see below), everything works fine. The output file is produced correctly. However when I hit this method from my MVC application, the exe fails to find the input file, even though it does exist. The only explanation I can think of for this is that the “TestResults” folders automatically created by VS2010 are different somehow in terms of permissions, or that the unit testing process is different somehow.

    public void Execute(string inputFileName, string outputFileName, int timeoutMilliseconds)
    {
        if (outputFileName == null)
            throw new ArgumentNullException("outputFileName");
        else if (inputFileName == null)
            throw new ArgumentNullException("inputFileName");

        if (outputFileName == string.Empty)
            throw new ArgumentException("outputFileName must not be an empty string");
        else if (inputFileName == string.Empty)
            throw new ArgumentException("inputFileName must not be an empty string");

        if (!File.Exists(ConfigurationManager.AppSettings["dataPath"]  + inputFileName))
            throw new FileNotFoundException("File not found.", inputFileName);            

        Process p = new Process();
        p.StartInfo = GetProcessStartInfo();
        p.Start();

        string output = "";

        // Read up to line where program asks for input file name.
        while (output == "")            
            output = p.StandardOutput.ReadLine();            

        // Write the input file name.
        p.StandardInput.WriteLine(inputFileName);

        // Read up to line where program asks for output file name.
        output = "";
        while (output == "")            
            output = p.StandardOutput.ReadLine();            

        // Write the output file name.
        p.StandardInput.WriteLine(outputFileName);

        if(!p.WaitForExit(timeoutMilliseconds))
            throw new ApplicationException("The process timed out waiting for a response.");            
    }

    private ProcessStartInfo GetProcessStartInfo()
    {
        var startInfo = new ProcessStartInfo();
        startInfo.CreateNoWindow = true;
        startInfo.UseShellExecute = false;
        startInfo.RedirectStandardOutput = true;
        startInfo.RedirectStandardInput = true;
        startInfo.FileName = _exeFileLocation;
        startInfo.WindowStyle = ProcessWindowStyle.Hidden;            
        return startInfo;
    }

EDIT:

I have discovered that the unit test also fails if I try to run the process from a location on my C drive. In the code below if I set “dataPath” to a hard disk location (e.g. “C:\DATALOCATION”), the process fails saying it can’t locate the input file. However if I leave “dataPath” in the config to an empty string, the unit test automatically runs the process from a subdirectory of the TestResults folder, and all works!

    [TestMethod]
    public void ExeRunnerTest()
    {
        var studyData = // populate study data here
        var writer = new StudyDataFileWriter(studyData);

        // Write input
        string fileName = writer.WriteToFile();

        // Run 
        var exeRunner = new ExeRunner(ConfigurationManager.AppSettings["dataPath"] + "myProcess.exe");
        exeRunner.Execute(fileName, "outputFile", 10000);

        // Read output
        IStudyOutputFileReader reader = new StudyOutputFileReader(ConfigurationManager.AppSettings["dataPath"] + "outputFile");
        StudyOutput output = reader.Read();

        // Tests
        Assert.AreEqual(1, output.ConsumerSummary.ConsumerTypes.Count());
    }
  • 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-11T23:08:14+00:00Added an answer on June 11, 2026 at 11:08 pm

    Using absolute paths got the code working. There must have been an issue with the working directory.

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

Sidebar

Related Questions

I have the following class which handles my user logged in / logged out
I have a Java class which handles both single valued and multi-valued data. Therefore,
I have class A which extends the Activity class. This class is in package
I have class Employee which is something like this. class Emp { int EmpID;
I have this class, instance of which I create in an AppDomain with no
I have an application that determines which path of execution to take based on
I have Camera class, which handles camera behavior. Among it's fields is a reference
I have a custom UIImageView class which I use to handle multi-touch events on
I have class which have one public method Start , one private method and
I have class LegacyClass which inherits OldBaseClass. I'm considering a change to introduce a

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.