views:

649

answers:

3

i have windows forms application wich runs another console application here is the part of code

prog = new Process();
prog.StartInfo.FileName = exefile;

the console application should create file but when running that application from C# it doesn't creates any file when im running console application with double click it works fine here is the part of code from "exefile" (its on c++)

freopen("file.in","r",stdin);
freopen("file.out","w",stdout);
printf("somedata\n");

"file.in" surely exists

please help me find out whats wrong thanks

+1  A: 

You need to add this line whenever you want to start the process:

prog.Start();

Here is the link to the MSDN page for Process.Start. There are several overloads that you may want to consider.

Andrew Hare
+2  A: 

The most likely thing is that you need to set the working path:

prog.StartInfo.WorkingDirectory = ...

i.e. I'm thinking it can't find file.in in the current app folder.

Marc Gravell
A: 

I would suggest,

  • handle exceptions to see what's going wrong
  • like mentioned before make sure you call the start() method

Here's a snippet of code from msdn, that you might want to refer

Process myProcess = new Process();

        try
        {
            // Get the path that stores user documents.
            string myDocumentsPath = 
                Environment.GetFolderPath(Environment.SpecialFolder.Personal);

            myProcess.StartInfo.FileName = myDocumentsPath + "\\MyFile.doc"; 
            myProcess.StartInfo.Verb = "Print";
            myProcess.StartInfo.CreateNoWindow = true;
            myProcess.Start();
        }
        catch (Win32Exception e)
        {
            if(e.NativeErrorCode == ERROR_FILE_NOT_FOUND)
            {
                Console.WriteLine(e.Message + ". Check the path.");
            } 

            else if (e.NativeErrorCode == ERROR_ACCESS_DENIED)
            {
                // Note that if your word processor might generate exceptions
                // such as this, which are handled first.
                Console.WriteLine(e.Message + 
                    ". You do not have permission to print this file.");
            }
        }
Vin