Problem with launching an external process
-
Hi, I am trying to write a console program that among other things will use the sqlplus utility to run PL/SQL script in a file. To this end I have the following bit of code:
static void execute(string command, string args, int timeout, string process_title)
{
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(command, args);
psi.RedirectStandardOutput = true;
psi.UseShellExecute = false;
System.Diagnostics.Process ps;
try
{
ps = System.Diagnostics.Process.Start(psi);if(!ps.WaitForExit(timeout)) { try { ps.Kill(); } catch(Exception e) { log("Error while trying to terminate process"); log("Error: "+e.Message); } throw new Exception(process\_title+" operation has timed out."); } } catch(Exception e) { log("Error Running "+process\_title); throw e; }
}
However when I run execute("sqlplus", @"mylogin/mypassword@sid @filepath", 50000, "my process"); I get a timeout, even if the file only contains a simple and small select clause. Any ideas? I suspect this is not sqlplus related since running execute("dir", @"C:\", 1000, "dir"); results in a "The system cannot find the file specified" error
-
Hi, I am trying to write a console program that among other things will use the sqlplus utility to run PL/SQL script in a file. To this end I have the following bit of code:
static void execute(string command, string args, int timeout, string process_title)
{
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(command, args);
psi.RedirectStandardOutput = true;
psi.UseShellExecute = false;
System.Diagnostics.Process ps;
try
{
ps = System.Diagnostics.Process.Start(psi);if(!ps.WaitForExit(timeout)) { try { ps.Kill(); } catch(Exception e) { log("Error while trying to terminate process"); log("Error: "+e.Message); } throw new Exception(process\_title+" operation has timed out."); } } catch(Exception e) { log("Error Running "+process\_title); throw e; }
}
However when I run execute("sqlplus", @"mylogin/mypassword@sid @filepath", 50000, "my process"); I get a timeout, even if the file only contains a simple and small select clause. Any ideas? I suspect this is not sqlplus related since running execute("dir", @"C:\", 1000, "dir"); results in a "The system cannot find the file specified" error
Can you not use the oracle drivers in .NET and execute the script through the common runtime? The reason you get the time out is because the application is likely waiting for input. I believe there is a WaitForInputIdle method which might suit you better.
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway -
Hi, I am trying to write a console program that among other things will use the sqlplus utility to run PL/SQL script in a file. To this end I have the following bit of code:
static void execute(string command, string args, int timeout, string process_title)
{
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(command, args);
psi.RedirectStandardOutput = true;
psi.UseShellExecute = false;
System.Diagnostics.Process ps;
try
{
ps = System.Diagnostics.Process.Start(psi);if(!ps.WaitForExit(timeout)) { try { ps.Kill(); } catch(Exception e) { log("Error while trying to terminate process"); log("Error: "+e.Message); } throw new Exception(process\_title+" operation has timed out."); } } catch(Exception e) { log("Error Running "+process\_title); throw e; }
}
However when I run execute("sqlplus", @"mylogin/mypassword@sid @filepath", 50000, "my process"); I get a timeout, even if the file only contains a simple and small select clause. Any ideas? I suspect this is not sqlplus related since running execute("dir", @"C:\", 1000, "dir"); results in a "The system cannot find the file specified" error
"dir" cannot be executed because there is no "dir.exe", it is just a command supported by cmd.exe. Can you try to disable RedirectStandardOutput? If you don't get a timeout then, your application is not handling the output fast enough. (the "sqlplus" process will pause when the output buffer is full)
-
"dir" cannot be executed because there is no "dir.exe", it is just a command supported by cmd.exe. Can you try to disable RedirectStandardOutput? If you don't get a timeout then, your application is not handling the output fast enough. (the "sqlplus" process will pause when the output buffer is full)
Yes, disabling redirect standard output works fine. Is there a way to deal with this short of editing the script file itself to turn spooling on? I would like the equivalent of 'sqlplus user/pass@sid @scriptfilename > logfilename', but not surprisingly, appending '> logfilename' to the arguments string doesn't work.
-
Yes, disabling redirect standard output works fine. Is there a way to deal with this short of editing the script file itself to turn spooling on? I would like the equivalent of 'sqlplus user/pass@sid @scriptfilename > logfilename', but not surprisingly, appending '> logfilename' to the arguments string doesn't work.
Found the answer here: http://weblogs.asp.net/israelio/archive/2004/08/31/223447.aspx how to pipe to a process just launch cmd.exe and pass everything to it as a parameter. Works great for me, anyone have any idea if this might be inferior for any reason? Why should I not just write a wrapper to launch all my prcoesses this way?