【发布时间】:2010-01-11 14:56:45
【问题描述】:
在我的网站中,我想对所有上传的文件进行病毒检查,然后再将它们保存到我的数据库中。所以我将文件保存到本地目录,然后从我的 C# 程序内部启动一个命令行扫描程序进程。这是我使用的代码:
string pathToScannerProgram = Path.Combine(virusCheckFolder, "scan.exe");
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = pathToScannerProgram;
startInfo.Arguments = String.Format("\"{0}\" /FAM /DAM", fileToScanPath);
startInfo.RedirectStandardOutput = true;
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.UseShellExecute = false;
using (Process process = new Process())
{
process.StartInfo = startInfo;
process.Start();
string output = process.StandardOutput.ReadToEnd();
string errorLevel = Environment.GetEnvironmentVariable("ERRORLEVEL");
process.WaitForExit();
}
我的问题是 Environment.GetEnvironmentVariable("ERRORLEVEL") 总是返回 null。它应该返回一个数字。那么如何在我的 C# 程序中获取命令行扫描器设置的“ERRORLEVEL”呢?
【问题讨论】:
标签: c# command-line environment-variables