I have my program which needs to run a ".BAT" file in IBM DB2 (db2cmd.exe). And log the contents of that console into a string, which I should be able to format.
Status quo is: The bat file contains username and password to the database, Export to csv query. The bat file when executed manually works absolutely fine.
The problem is that I am not able to capture the details of that console into a string.
Code snippet is as follows:
proc.StartInfo.FileName = "db2cmd.exe";
proc.StartInfo.Arguments = @"C:\test.bat";
proc.StartInfo.WorkingDirectory = @"C:\Program Files\IBM\SQLLIB\BIN\";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.OutputDataReceived += (o, e) => s.AppendLine(e.Data);
proc.ErrorDataReceived += (o, e) => s.AppendLine(e.Data);
proc.Start();
proc.BeginOutputReadLine();
proc.BeginErrorReadLine();
proc.WaitForExit();
code = proc.ExitCode;
Using -i option with db2cmd.exe should fix this issue. Modify first line of your program as below: