Shell command in c#

I am trying to use a shell command in c# to call a program which is installed on the server and I found an example in the Help files but it is throwing all sorts of errors, can someone give me some advise on how to do this, I previously did it in VB and it worked well.

thanks in Advance
CJSantora
CJSantoraAsked:
Who is Participating?
 
jatinderalaghCommented:
Example of ping :
 
 Process myCmd = null;
               ProcessStartInfo qOptions = new ProcessStartInfo(@"cmd.exe", @"/C ping 127.0.0.1");
               qOptions.WindowStyle = ProcessWindowStyle.Hidden;

               qOptions.RedirectStandardOutput = true;  // set to "true" to enable logging
               qOptions.UseShellExecute = false;  // set to true to make silent/background
               
               myCmd = Process.Start(qOptions);

               StreamReader str = myCmd.StandardOutput;
               Console.WriteLine(str.ReadToEnd());
               
               myCmd.WaitForExit();


This essentially runs the ping command and returns the results to a string.  You will now have a string field with all of the contents that were returned.  You can do a simple query to determine if the results are a success or failure.

you can make it as background also
 qOptions.UseShellExecute = false;  // set to true to make silent/background


The line of code above... if you set it to true to make the process "silent" you won't be able to get a screen re-direct text.  

But then you need to redirect the output to some file or so.
0
 
Éric MoreauSenior .Net ConsultantCommented:
you have to use Process.Start
0
 
Éric MoreauSenior .Net ConsultantCommented:
0
 
plqCommented:
I think its System.Diagnostics.Process.Start(...)

0
 
CJSantoraAuthor Commented:
Thank You for your help jatinderalagh
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.