Avatar of katlin924
katlin924Flag for Philippines asked on

Show in MessageBox a command-line output

I am trying to output the version of the mk32. I already searched for some answers here in EE but it's still not working. Here's the code:

            string Output = "";

            Process ProcessObj = new Process();
                 
            ProcessObj.StartInfo.Arguments = "-v";
            ProcessObj.StartInfo.UseShellExecute = false;
            ProcessObj.StartInfo.RedirectStandardOutput = true;
            ProcessObj.StartInfo.FileName = @"C:\usr\local\bin\mk32.exe";
            ProcessObj.Start();

            Output = ProcessObj.StandardOutput.ReadToEnd();

            MessageBox.Show(Output, "mk32 Version");

It just gives me a blank output.

Can anyone please tell me what's wrong with the code?
Thanks so much for the help!
.NET ProgrammingC#Microsoft DOS

Avatar of undefined
Last Comment
katlin924

8/22/2022 - Mon
rendaduiyan

add "ProcessObj.WaitForExit();" to flush the output stream.
string Output = "";

            Process ProcessObj = new Process();
                 
            ProcessObj.StartInfo.Arguments = "-v";
            ProcessObj.StartInfo.UseShellExecute = false;
            ProcessObj.StartInfo.RedirectStandardOutput = true;
            ProcessObj.StartInfo.FileName = @"C:\usr\local\bin\mk32.exe";
            ProcessObj.Start();

            Output = ProcessObj.StandardOutput.ReadToEnd();


            ProcessObj.WaitForExit();

            MessageBox.Show(Output, "mk32 Version");
ASKER
katlin924

I tried it already but it doesn't work.

Attached is the image when I run it in cmd.exe.
I need to output the Version.


mk32.gif
ASKER
katlin924

I'm sorry to disturb all your precious time. It seems that the command "mk32 -v" doesn't really gives an output. The code above works perfectly fine. I tried other commands and it worked.

The problem might be the mk32.exe itself. I tried redirecting it in a file but I didn't any output.

I will just figure out something on how to get the version of the exe file.

Thanks so much for answering.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
ASKER CERTIFIED SOLUTION
pratap_r

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
katlin924

Thanks so much for the solution. :) You're great!