Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Problem with launching an external process

Problem with launching an external process

Scheduled Pinned Locked Moved C#
toolshelpdatabaseoraclequestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Togakangaroo
    wrote on last edited by
    #1

    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

    E D 2 Replies Last reply
    0
    • T Togakangaroo

      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

      E Offline
      E Offline
      Ennis Ray Lynch Jr
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • T Togakangaroo

        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

        D Offline
        D Offline
        Daniel Grunwald
        wrote on last edited by
        #3

        "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)

        T 1 Reply Last reply
        0
        • D Daniel Grunwald

          "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)

          T Offline
          T Offline
          Togakangaroo
          wrote on last edited by
          #4

          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.

          T 1 Reply Last reply
          0
          • T Togakangaroo

            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.

            T Offline
            T Offline
            Togakangaroo
            wrote on last edited by
            #5

            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?

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups