[英]c# running command line with two arguments
so I'm currently working on a BlueJ like clone for c#. 所以我目前正在为C#开发像BlueJ这样的克隆。 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. 现在,我要在工作文件夹中编译使用的所有.cs文件: C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\csc.exe /define:DEBUG /optimize /out:Program.exe *.cs
我从msdn页面获取的C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\csc.exe /define:DEBUG /optimize /out:Program.exe *.cs
。 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. 为了使它正常工作,我需要使用正确的定向程序,因此我使用以下命令: cd /d + dir
其中dir是文件的定向程序。 Now when I try to run that from c# like this: 现在,当我尝试从c#运行如下代码时:
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. 但是,当我尝试在cmd窗口中运行命令时,它可以正常运行。 Any ideas? 有任何想法吗?
Run the command with 使用以下命令运行命令
cmd.exe /c
cmd.exe expects parameter "/c" if you want to pass over an execution command. 如果要传递执行命令,则cmd.exe需要参数“ / c”。
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 应该管用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.