screen scraping dos application

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • newdev
    New Member
    • Dec 2009
    • 1

    screen scraping dos application

    Hi All,

    Can somebody maybe please help me?

    - how do i screen scrape data from a dos application / window to .net application by using c#?
    - how do i screen scrape data from a dos application / window to sql database?
    - how do i screen scrape data from a dos application / window to sql database and insert other data back to the dos application / window?

    Thanks
  • NitinSawant
    Contributor
    • Oct 2007
    • 271

    #2
    Dear,
    Hear's function for doing the task,

    executes the command using cmd and returns the output as text

    Code:
    public String ExecuteCommandSync(object command)
            {
                try
                {
                    // create the ProcessStartInfo using "cmd" as the program to be run, and "/c " as the parameters.
                    // Incidentally, /c tells cmd that we want it to execute the command that follows, and then exit.
                    System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo("cmd", "/c " + command);
                    // The following commands are needed to redirect the standard output. 
                    //This means that it will be redirected to the Process.StandardOutput StreamReader.
                    procStartInfo.RedirectStandardOutput = true;
                    procStartInfo.UseShellExecute = false;
                    // Do not create the black window.
                    procStartInfo.CreateNoWindow = true;
                    // Now we create a process, assign its ProcessStartInfo and start it
                    System.Diagnostics.Process proc = new System.Diagnostics.Process();
                    proc.StartInfo = procStartInfo;
                    proc.Start();
    
                    // Get the output into a string
                    string result = proc.StandardOutput.ReadToEnd();
    
                    // Display the command output.
                    return result;
                }
                catch(Exception ex)
                {
                    // Log the exception
                    //return "";
                    throw ex;
                }
            }

    Comment

    Working...