我试图使用Asp.Net C#将命令提示符输出重定向到一个文件。如何使用asp.net C#将命令提示符输出重定向到文件?
System.Diagnostics.Process si = new System.Diagnostics.Process();
si.StartInfo.WorkingDirectory = "c:\\";
si.StartInfo.UseShellExecute = false;
si.StartInfo.FileName = "cmd.exe";
si.StartInfo.Arguments = @"/c dir" +">" + @"Myval.txt";
si.StartInfo.CreateNoWindow = true;
si.StartInfo.RedirectStandardInput = true;
si.StartInfo.RedirectStandardOutput = true;
si.StartInfo.RedirectStandardError = true;
si.Start();
string output = si.StandardOutput.ReadToEnd();
Response.Write(output);
si.Close();
该文件正在成功创建,但没有内容出现在它中。 即使变量Output
也不会返回任何结果。 帮我解决这个问题。修正后的
在一个侧面说明,什么是你想怎么办?由于安全限制,您很有可能无法在托管环境中调用此类命令。 – Alexander
我想在服务器控制台执行一个exe文件,以便从用户输入中提取一些值并将输出收集到一个文件中。 – Dinesh
您至少需要一个FullTrust托管环境,而不是所有这些都允许您运行可执行文件。 – Alexander