|
-
February 3rd, 2011, 05:30 PM
#1
[RESOLVED] Run cmdline code with C#
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:
Code:
//--- 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...
Last edited by DemonPiggies; February 4th, 2011 at 12:45 PM.
Reason: Forgot code tags, sorry...
-
February 3rd, 2011, 06:07 PM
#2
Re: Run cmdline code with C#
try this
Code:
using System.IO;
.....
ProcessStartInfo ProcessInfo;
Process Process;
ProcessInfo = new ProcessStartInfo(@"C:\windows\system32\cmd.exe", @"""C:\Program Files\Microsoft Visual Studio\COMMON\msdev98\Bin\msdev.exe"" ""c:\cql\source\mainline\souce\create\cql.dsw /MAKE cql_ii - Win32 Release""");
ProcessInfo.CreateNoWindow = true;
ProcessInfo.UseShellExecute = false;
Process = Process.Start(ProcessInfo);
Process.Close();
there is no need for \\ , when you use paths like this @"your path here"
Last edited by invader7; February 3rd, 2011 at 06:10 PM.
-
February 4th, 2011, 12:41 PM
#3
Re: Run cmdline code with C#
So apparently I misspelled the file's path which was problem #1.
Problem #2 is that I couldn't get invader7's code to work correctly which is my fault.
I needed quotation marks around the compiler type.
For whatever reason, I can't call C:\Program Files\Microsoft Visual Studio\COMMON\msdev98\Bin\msdev.exe directly but I can use msdev though. I'm not sure why I can't call msdev.exe as a parameter of cmd.exe using C#. Let me clarify real quick. I can call msdev.exe through cmd.exe and somehow I can pass in the file path too but I could [b]not[b] get it to compile by sending the Make command as a parameter in the same string. Maybe it's too many parameters for cmd.exe? Or I'm calling it wrongly?
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);
Last edited by DemonPiggies; February 4th, 2011 at 12:44 PM.
Reason: added clarification...
-
February 4th, 2011, 02:51 PM
#4
Re: Run cmdline code with C#
Have you thought about using any one of the multiple applications already available for organizing builds?
-
February 4th, 2011, 11:20 PM
#5
Re: Run cmdline code with C#
VS has a built in setup. If you want scripting, look at Powershell 2.0
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|