Trapping output from a command prompt

Associate
Joined
27 Jan 2005
Posts
1,395
Location
S. Yorks
Following on from my question regarding running a data reduction tool through excel I am trying to do the same with VB.NET2008.

Now I can run the tool and redirect the output so I can trap it, basicly I am looking for a line that says "press any key" as this signifies the program has finished. The problem I have is that because I am reading 100,000 to 200,000 lines it is having a massive overhead, is there a way to read say every 1000the line of output?

Suppose other option is output to a file but am not sure if I could reasd this other file whilst it is still open?

regards,

Matt
 
You can't read another file while one is open, you need to close the file stream object that reads before you can create one that writes.

As for the 'press any key' thing, just use Console.Read(); (i think it's that but it's been a long time since i've used VB.NET).

I'm still not quite sure what your trying to do with the main part of the program mind you, are you trying to read an excel document or something? Maybe post a bit of code which would give a better idea on what your trying to achieve :)
 
What do you mean by overhead? Memory use? In which case, just use a circular buffer. Make sure you truncate at a line break.

Can the program not be configured to quit without asking for a keypress?
 
I have gone down the route of the console.readline but because the displayed output to the command prompt amounts to between 100,000 to 200,000 it slows the process down dramaticly - Whilst the output to the command prompt is being written approx 400 files are being written to, the process time for the operation can take between 10 mins and 5 hours depending on original file size.

Have tried the console.readtoend but this just waits even when the process finishes at the line "press any key" I presume console.readtoend doesn't know it has actually finished.

As for what I am trying to do...

We have a Data processing tool and an excel spreadsheet that reads the ouput files from the data processing tool, its a labour intensive process to get the files to process in the data reduction tool and then read them into the excel spreadsheet so I am trying to automate the entre task.

Data tool..

This accepts 3 files as command arguments, as it is being run it outputs info to the command prompt and also writes to a number of files, when the Data tool has finished it prompts for the user to press any key to continue. We do not have access to the source code for this.

Excel spreadsheet...

This reads in the processed files and produces a huge amount of output.

I can run the data tool through excel or vb.net what I cannot do is work out how to handle the point at which the data tool finishes and is sat waiting for the user to press any key. Have tried to monitor cpu useage but the data tool sits idle part way through the process for a min or so, I assume another process is running at this point this is also intermittent depending on what file is being processed. Have tried the read command prompt output but it slows the process down hugely.

Anyone have anymore ideas?

regards,

Matt
 
Last edited:
Code:
            var startInfo = new ProcessStartInfo(@"PressAnyKey.exe");
            startInfo.RedirectStandardOutput = true;
            startInfo.RedirectStandardInput = true;
            startInfo.UseShellExecute = false;

            Process p = Process.Start(startInfo);

            while (true)
            {
                string line = p.StandardOutput.ReadLine();
                if (line == "Press any key...")
                {
                    p.StandardInput.Write("x");
                    p.StandardInput.Flush();
                    break;
                }
            }

            p.WaitForExit();
 
Back
Top Bottom