I have a C# project where I use the Process class to run R scripts:
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());
}
The R scripts I run use RODBC to connect to a database to get data. However whenever I run a query through my RODBC connection it prints the ODBC driver logging info (which has tracing set to 0) to the process StandardError. How can I either just make it log this to info or not log it at all? I want to be able to use Standard error to actually detect errors, but I can't with this happening as there is always an error stream.
RODBC is not doing the logging; this is caused by the ODBC connector (in this case, the Snowflake ODBC connector) trying to open a log file which is already opened by another script's ODBC connector, and instead logging to stderr without filtering.
You can see this by running two scripts at once that use the ODBC connector. Setting TRACE=1
as an environmental variable for the second will also give simba logs, which include a "cannot open file message" - using procmon will show that the file in question is the default log file.