我有一个C#项目,我使用Process类来运行R脚本:
public void RunRScriptFile(string file) {
StringBuilder eventLog = new StringBuilder();
StringBuilder errorLog = new StringBuilder();
var scriptRunProcess = new Process {
StartInfo = new ProcessStartInfo {
FileName = "Rscript",
Arguments = file,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = false
}
};
scriptRunProcess.Start();
while (!scriptRunProcess.StandardOutput.EndOfStream) {
eventLog.AppendLine(scriptRunProcess.StandardOutput.ReadLine());
}
while (!scriptRunProcess.StandardError.EndOfStream) {
errorLog.AppendLine(scriptRunProcess.StandardError.ReadLine());
}
Log.AddEvent(new List<String>() { "Info" }, eventLog.ToString());
if (errorLog.Length > 0) Log.AddEvent(new List<string>() { "Info", "Warning", "Critical" }, errorLog.ToString());
}
我运行的R脚本使用RODBC连接到数据库以获取数据。但是,每当我通过RODBC连接运行查询时,它都会将ODBC驱动程序日志信息(其跟踪设置为0)打印到进程StandardError。我怎样才能将其记录到信息或不记录?我希望能够使用标准错误来实际检测错误,但我无法解决这个问题,因为始终存在错误流。