views:

38

answers:

2

I have an application with a Process that use a cmd program. The Process's output is redirect like so:

pr.StartInfo.RedirectStandardOutput = true;
pr.StartInfo.UseShellExecute = false;
pr.StartInfo.CreateNoWindow = true;                                         
pr.EnableRaisingEvents = true
pr.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
pr.OutputDataReceived += new DataReceivedEventHandler(OnDataReceived);      
pr.ErrorDataReceived += new DataReceivedEventHandler(OnDataReceived); 

The output is then written to the console using:

public void OnDataReceived(object sender, DataReceivedEventArgs e)
{
    if(e.Data != null)                                  
    {
        Console.WriteLine(e.Data);
    }
}

My problem is the Visual Studio prints the output, it's very different to the commandline output. For example, I'm trying to extract data from the output to see how much work has been done. My application output:

0K .......... .......... .......... .......... .......... 1% (null)
50K .......... .......... .......... .......... .......... 2% (null)
100K .......... .......... .......... .......... .......... 3% (null)
150K .......... .......... .......... .......... .......... 5% (null)

The original Commandline program output (progress bar and percentage accumulates as time goes on):
100%[===================================]

It may not seem a big difference, but for what I'm trying to achieve it is. Why isn't Visual Studio output exactly the same as the CMD out?

Ps. Arguments are the same in both examples.

A: 

A console and a file is very different. The progress bar clearly uses some special console specific features that are not present when redirecting (which is effectively a file).

leppie
+1  A: 

That's because wget is detecting that you're not running with a visible console. There are arguments with which you can change this.

The reason for this specifically is that the way wget builds the [==== is by overwriting the current line. The output you would see through the redirect would probably be something like this:

  5% [=
 10% [==
 15% [===
 20% [====

etc. All of them on a new line.

You can force this type of feedback by adding --progress=bar to the arguments.

Pieter
It's wput, not wget. Not sure how much difference that makes.
johnnyturbo3
The same should go for `wput`. Have you tried adding the progress bar argument?
Pieter
Yes. Unfortunately, wput does not provide this argument:
johnnyturbo3
http://wput.sourceforge.net/wput.1.html
johnnyturbo3
Hmmm. That's a shame. Irritating when applications try to be smart :).
Pieter