0

Hello I've to Launch the software CFast for a Parametric Analysis. To do this, I want to create a application in C# that runs the core CFast.exe. If I want run the software from cmd.exe and execute it on the file INPUTFILENAME.in I write in prompt:

CFast.exe INPUTFILENAME

In C# I wrote the following code:

Process firstProc = new Process();
firstProc.StartInfo.FileName = @"C:\Users\Alberto\Desktop\Simulazioni Cfast\D\C\N\A3B1\CFAST.exe";
firstProc.StartInfo.Arguments = @"INPUTFILENAME";
firstProc.EnableRaisingEvents = true;
firstProc.Start();
firstProc.WaitForExit();

With this code CFast run but doesn't analyze anything... Seems like don't accept the argument. Hint for this trouble ?

Locen0
  • 11
  • 1
  • 3
  • is INPUTFILENAME arguement or the name of the file? Is the filename correct? – nobody Feb 28 '16 at 22:00
  • What do you mean by it didn't process anything? It didn't execute? – CodingMadeEasy Feb 28 '16 at 22:00
  • @inquisitive_mind It's the filename and it is correct. – Locen0 Feb 28 '16 at 22:03
  • @CodingMadeEasy The application starts but closes immediately as it does when it is launched without the input fle – Locen0 Feb 28 '16 at 22:05
  • Well you don't seem to run it with the full path in the cmd line. So why not set the CWD in the process startinfo to see if that works. Maybe CFast.exe relies on that. Also you may want to check the errors and output to see if there's something you're missing. – CodingMadeEasy Feb 28 '16 at 22:13
  • @CodingMadeEasy I tryed to move the input file in the Installation Directory of cFast and it doesn't work. There are no Errors and output... – Locen0 Feb 28 '16 at 22:18
  • Is CFast.exe set to "Run as Administrator"? If so, your c# app will also need to be running as administrator to pass it command line arguments. – Lorek Feb 28 '16 at 22:33

1 Answers1

0

Solved. Mistake in the filename and in the syntax of the command

// setup cmd process
        var command = @"CFAST.exe C:\Users\Alberto\Desktop\Simulazioni_Cfast\D\C\N\A3B1\A3B1";
        ProcessStartInfo procStartInfo = new ProcessStartInfo("cmd", "/c " + command);
        procStartInfo.RedirectStandardOutput = true;
        procStartInfo.UseShellExecute = false;
        procStartInfo.RedirectStandardError = true;
        procStartInfo.CreateNoWindow = true;

        // start process
        Process proc = new Process();
        proc.StartInfo = procStartInfo;
        proc.Start();

        proc.WaitForExit();

        // read process output
        string cmdError = proc.StandardError.ReadToEnd();
        string cmdOutput = proc.StandardOutput.ReadToEnd();

where A3B1 is the name of the file .IN

Locen0
  • 11
  • 1
  • 3