【发布时间】:2012-02-27 13:47:32
【问题描述】:
我有以下代码
using (StreamWriter outfile = new StreamWriter(@"f:\trial.cpp"))
{
outfile.Write(txtCode.InnerText);
}
System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo(@"cl.exe", @" 'trial.cpp'");
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
procStartInfo.UserName = "asdasd";
SecureString secureString = new SecureString();
foreach (char c in "abcded")
{
secureString.AppendChar(c);
}
procStartInfo.Password = secureString;
// Do not create the black window.
procStartInfo.CreateNoWindow = true;
procStartInfo.WorkingDirectory = @"f:\";
// Now we create a process, assign its ProcessStartInfo and start it
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo = procStartInfo;
proc.Start();
// Get the output into a string
string result = proc.StandardOutput.ReadToEnd();
如何将文件名作为参数传递?上面的代码没有运行,我已经尝试了所有的完整路径,不同的路径选项。
谁能帮忙?
【问题讨论】:
-
没有运行?错误是什么??
-
定义“不运行”。解释确切什么正在发生以及您期望发生什么。
-
“不运行”是什么意思?进程未启动?命令行参数错误?
-
用字符串参数交换'@"f:\trial.cpp"'?此外,在处理之前确保文件存在可以解决问题,例如if ( new System.IO.FileInfo( yourFileAndPath ).Exists )...
-
“不运行”的意思是,它不会产生任何输出。结果字符串中只有“Trial.cpp”,没有任何意义。我检查了trial.cpp所在的目录,没有putput文件,检查了cl.exe目录和c:\windows\system32,没有输出。
标签: c# process.start cl.exe