How do I get the "ERRORLEVEL" variable set by a command line scanner in my C# program?
c#, command-line, environment-variables
Solution
As far as I know that is just the ExitCode of your Process. Use that.
And it would only be useful to check that after waiting for the process to end, btw.
Problem
In my website I want to virus-check any uploaded files before saving them into my database. So I save the file to the local directory then kick-off a command-line scanner process from inside my C# program. Here is the code I use: ``` 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(); } ``` My problem is that Environment.GetEnvironmentVariable("ERRORLEVEL") is always returning null. It should be returning a number. So how do I get the "ERRORLEVEL" set by the command line scanner in my C# program?