Shell command in c#

Posted on 2005-05-07
Last Modified: 2008-02-26
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
Question by:CJSantora
    LVL 69

    Expert Comment

    by:Éric Moreau
    you have to use Process.Start
    LVL 69

    Expert Comment

    by:Éric Moreau
    LVL 8

    Expert Comment

    I think its System.Diagnostics.Process.Start(...)

    LVL 11

    Accepted Solution

    Example of ping :
     Process myCmd = null;
                   ProcessStartInfo qOptions = new ProcessStartInfo(@"cmd.exe", @"/C ping");
                   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;

    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.

    Author Comment

    Thank You for your help jatinderalagh

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
    Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now