Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run commandline with C#

Status
Not open for further replies.

Demonpiggies

Programmer
Apr 9, 2007
42
0
0
US
I'm trying to eliminate our dependence on batch files for compiling our many projects. I am forced to use a huge batch file to create our installation and am just tired of all my co-workers' questions about how to compile certain projects. So I'm trying to create an application in C# that will dynamically compile, register, delete, etc the projects that a specific project.

The problem I'm having is that I cannot execute commandline code from C#. I used the examples that I've found on MSDN, CodeGuru, etc. and below is what I've come up with. I've used the code from the batch file that is supposed to usable by commandline. But when I run the code below all I get is a cmd window that points to the debug folder of the project itself (not the one I need compiled).

Here's most of my code, or at least the portion that will execute the commandline:

//--- create process member
System.Diagnostics.Process compilerProcess;
compilerProcess = new System.Diagnostics.Process();
compilerProcess.EnableRaisingEvents = false;
compilerProcess.StartInfo.FileName = @"C:\\windows\\system32\\CMD.exe";
compilerProcess.StartInfo.Arguments = "C:\\Program Files\\Microsoft Visual Studio\\COMMON\\msdev98\\Bin\\msdev.exe c:\\cql\\source\\mainline\\souce\\create\\cql.dsw /MAKE cql_ii - Win32 Release";
compilerProcess.StartInfo.UseShellExecute = false;
compilerProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
compilerProcess.StartInfo.CreateNoWindow = true;
compilerProcess.StartInfo.RedirectStandardOutput = true;
compilerProcess.Start();
compilerProcess.WaitForExit();
rtfOutput.Text = compilerProcess.StandardOutput.ReadToEnd().ToString();
compilerProcess.Close();


Any help in this is appreciated...
 
why not use a build system that already exists? nant and psake are designed specifically for this. easy to configure, command line friendly, works great with CI servers.

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Before replying I did look at Nant and pSake. These are complex answers to my simple need. I want to eliminate the my use and my user's interactions with commandline and batch file code. I understand that I still want to use CMD to do my work but now I do not have to physically go thru and edit the code or have my co-workers muddle thru my batch files (some of them do not really get it). I mainly want to create a GUI that a user will easily understand and just be able to pick and choose which projects to build (and then their dependencies) and then go about registering, backing up, etc. Thanks for the suggestion jmeckley but I can't really use it.

Anyway here's the correct code (because I hate when people say things are solved but never show their answer):
Code:
ProcessStartInfo startInfo = new ProcessStartInfo("msdev");
startInfo.Arguments = @"""c:\cql\source\mainline\source\create\cql.dsw"" /Make ""cql_ii - Win32 debug""";
Process.Start(startInfo);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top