0

so I'm currently working on a BlueJ like clone for c#. Now I want to compile all the .cs files in the working folder on click for which I use: C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe /define:DEBUG /optimize /out:Program.exe *.cs which I took from the msdn page. For that to work though I need to be in the right directionary so I use the following: cd /d + dir where dir is the directionary of the files. Now when I try to run that from c# like this:

cmd = @"cd /d "+ dir + @" && C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe /define:DEBUG /optimize /out:Program.exe *.cs"; file = "cmd"; var proc = new Process(); proc.StartInfo = new ProcessStartInfo(file, cmd); proc.StartInfo.RedirectStandardOutput = true; proc.StartInfo.RedirectStandardError = true; proc.EnableRaisingEvents = true; proc.StartInfo.CreateNoWindow = true; proc.StartInfo.UseShellExecute = false; proc.ErrorDataReceived += proc_DataReceived; proc.OutputDataReceived += proc_DataReceived; proc.Start(); proc.BeginErrorReadLine(); proc.BeginOutputReadLine(); 

nothing happenes. But when I try to run the command in the cmd window it works fine. Any ideas?

0

1 Answer 1

1

Run the command with

cmd.exe /c 

cmd.exe expects parameter "/c" if you want to pass over an execution command.

So:

cmd = @"/c cd /d "+ dir + @" && C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe /define:DEBUG /optimize /out:Program.exe *.cs"; 

should work

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the anwser but now even less happenes since this doesn't even work when using the console. It now tells me that it couldn't find the command /c couldnt be found

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.