0

I have to monitor an url that keeps streaming status of the system. If i issue following command from Windows CMD curl.exe http://localhost:8081/statusstream, I keep getting output from stream:

[02:10:51.021] Starting to execute testcase
[02:10:51.021] Test01: Preparing 
[02:11:03.089] Test01: Executing 1/10
[02:11:11.109] Test01: Executing 2/10
[02:11:19.126] Test01: Executing 3/10
[02:11:27.145] Test01: Executing 4/10
[02:11:35.163] Test01: Executing 5/10
[02:11:43.181] Test01: Executing 6/10
[02:11:51.198] Test01: Executing 7/10
[02:11:59.220] Test01: Executing 8/10
[02:12:07.237] Test01: Executing 9/10
[02:12:15.255] Test01: Executing 10/10
[02:12:33.274] Test01: Transferring data for analysis
[02:12:41.562] WARNING: TestSequencer: No data found
[02:12:41.563] Test01: Analyze results
[02:12:42.064] Test01: Finished executing
[02:12:42.064] Finished executing testcase

However when I run the same command using C#, I don't get any standard output, all I get is standard error. Following is my C# code

ProcessStartInfo _processStartInfo = new ProcessStartInfo();
_processStartInfo.RedirectStandardOutput = true;
_processStartInfo.RedirectStandardError = true;
_processStartInfo.UseShellExecute = false;
_processStartInfo.CreateNoWindow = true;
_processStartInfo.FileName = "curl.exe"
_processStartInfo.Arguments = "http://localhost:8081/statusstream";

_process = new Process();
_process.StartInfo = _processStartInfo;
_process.EnableRaisingEvents = true;
_process.StartInfo.RedirectStandardOutput = true;
_process.StartInfo.RedirectStandardError = true;
_process.ErrorDataReceived += _process_ErrorDataReceived;
_process.OutputDataReceived += _process_OutputDataReceived;
_process.Exited += _process_Exited;

_process.Start();

_process.BeginOutputReadLine();
_process.BeginErrorReadLine();

The following method is always being hit, but not the the one which is waiting for StandardOutput

private void _process_ErrorDataReceived(object sender, DataReceivedEventArgs e)
{
    if (!string.IsNullOrEmpty(e.Data))
        this.ConsoleLog = string.Format("[StdErr] {0}",e.Data);           
}

Output that i get from running CURL command from C# is:

    [StdErr]   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
    [StdErr]                                  Dload  Upload   Total   Spent    Left  Speed
    [StdErr]   0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
    [StdErr] 100    40    0    40    0     0     33      0 --:--:--  0:00:01 --:--:--    33
    [StdErr] 100    40    0    40    0     0     18      0 --:--:--  0:00:02 --:--:--    18
    [StdErr] 100    40    0    40    0     0     12      0 --:--:--  0:00:03 --:--:--    12
    [StdErr] 100    40    0    40    0     0      9      0 --:--:--  0:00:04 --:--:--     9
    [StdErr] 100    40    0    40    0     0      7      0 --:--:--  0:00:05 --:--:--     7
    [StdErr] 100    40    0    40    0     0      6      0 --:--:--  0:00:06 --:--:--     0
    [StdErr] 100    40    0    40    0     0      5      0 --:--:--  0:00:07 --:--:--     0
    [StdErr] 100    40    0    40    0     0      4      0 --:--:--  0:00:08 --:--:--     0
    [StdErr] 100    40    0    40    0     0      4      0 --:--:--  0:00:09 --:--:--     0
    [StdErr] 100    40    0    40    0     0      3      0 --:--:--  0:00:10 --:--:--     0
    [StdErr] 100    40    0    40    0     0      3      0 --:--:--  0:00:11 --:--:--     0
    [StdErr] 100    40    0    40    0     0      3      0 --:--:--  0:00:12 --:--:--     0
    [StdErr] 100   112    0   112    0     0     16      0 --:--:--  0:00:06 --:--:--    16
    [StdErr] 100   250    0   250    0     0     32      0 --:--:--  0:00:07 --:--:--    47
    [StdErr] 100   250    0   250    0     0     29      0 --:--:--  0:00:08 --:--:--    47
    [StdErr] 100   250    0   250    0     0     26      0 --:--:--  0:00:09 --:--:--    47

If I see the received column, its value increases from 40 to 250, that means probably something is being return from the stream.

Issuing other HTTP GET commands from CURL using C# gives proper standardoutput. But other get commands return content immediately and are not streaming continuously.

Can someone please point what I'm doing wrong.


Ok, so I'm not supposed to call cURL.exe from C# code. But is there a way where I can monitor a URL to get continuous stream of data whenever there are updates? I don't want to call HttpClient GetStringAsync in a while loop.

sunny days
  • 837
  • 1
  • 13
  • 26
  • possible duplicate of [Making a cURL call in C#](http://stackoverflow.com/questions/7929013/making-a-curl-call-in-c-sharp) – NightOwl888 Mar 19 '15 at 12:42
  • Ok, so I'm not supposed to call cURL.exe from C# code. But is there a way where I can monitor a URL to get continuous stream of data whenever there are updates? I don't want to call HttpClient GetStringAsync in a while loop. – sunny days Mar 19 '15 at 13:25
  • Use a timer to make the call every X seconds. – Jonathon Reinhart Mar 19 '15 at 13:28

0 Answers0