0

I am generating C++ code via C#, for some reason after applying astyle my generated code compiles. So is there a way I can invoke astyle from within my C# windows application?

Toon Krijthe
  • 52,876
  • 38
  • 145
  • 202
kingpin
  • 83
  • 3
  • 12
  • 1
    Wouldn't it be easier to figure out what "for some reason" is and fix it in your generator? – Duck Apr 06 '12 at 05:02

2 Answers2

0

Astyle is a command line tool, so using Process class you can call it externally and ask it to format the C++ source file.

I have done similar projects in the past, such as

http://alex.codeplex.com

Lex Li
  • 60,503
  • 9
  • 116
  • 147
0

I finally figured it out a few days ago, so thought i would share my function to astyle via c#

' private void astyleDirectory(string target_path) { System.Diagnostics.Process pProcess = new System.Diagnostics.Process(); //Enter Path to get Astyle.exe here pProcess.StartInfo.FileName=System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\Astyle.exe";

       pProcess.StartInfo.Arguments = "--options=none --style=ansi --recursive  *.h *.cpp";
       pProcess.StartInfo.UseShellExecute = false;
       pProcess.StartInfo.RedirectStandardOutput = true;
       pProcess.StartInfo.RedirectStandardError = true;
       pProcess.StartInfo.WorkingDirectory = System.IO.Path.GetDirectoryName(target_path);
       try
       {
           pProcess.Start();
           string strOutput = pProcess.StandardOutput.ReadToEnd();
           string strError = pProcess.StandardError.ReadToEnd();
           pProcess.WaitForExit();

       }
       catch { }
   }

'

kingpin
  • 83
  • 3
  • 12