Trying to capture stdoutput, but Diagnostics.Process object causes process to hang

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JustinCase
    New Member
    • Jul 2010
    • 1

    Trying to capture stdoutput, but Diagnostics.Process object causes process to hang

    Hi, I'm trying to capture the standard output from a program called cURL.

    Running the program from the command line as such:

    >curl www.youtube.com

    will write out the HTML page returned by YouTube.

    My objective is to "capture" and manipulate this data. I read about the systems.diagnos tics.process class and its ability to redirect stdoutput/stdinput and thought it would be perfect -- apparently not.

    Here is the relevant code:

    Code:
    Diagnostics.Process curl = new Diagnostics.Process();
    String response = null;
    curl.StartInfo.FileName = curlPath;
    curl.StartInfo.UseShellExecute = false;
    curl.StartInfo.RedirectStandardOutput = true;
    curl.StartInfo.Arguments = "www.msn.com";
    curl.start();
    curl.WaitForExit(40000);
    if (curl.HasExited) {
    	response = curl.StandardOutput.ReadToEnd;
    } else {
    	curl.Kill();
    }
    When the process is started, rather than spitting out the HTML of YouTube.com, I get a meter displaying download progress. Obviously this is something built into cURL, but why is it doing it? I want the process to be ran just as it is from the command line. The major issue, though, is that cURL will just hang after downloading a few bytes.

    What's going on here? Why is it behaving differently than when it's called from the command line? And how can I "simulate" the command line? I tried executing cmd.exe instead, and then writing the command "curl www.youtube.com " to stdin, but that caused even more problems...

    Any help/explanation is appreciated.
  • Alex Papadimoulis
    Recognized Expert New Member
    • Jul 2010
    • 26

    #2
    While I'm not very familiar with how cURL works, I'm curious as to why you are trying to download a page using a command line?

    The WebClient class provides methods to retreive web pages from a URL in the same manner that it looks like you're using.

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      You can use the HttpWebRequest class to make a request to a website and retrieve the HTML for the page.

      -Frinny

      Comment

      Working...