Thread: Sending Shell Commands

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    3

    Question Sending Shell Commands

    I want to use C# to send a command to the shell. I dont want to open an external application I just want to send a command such as the PAUSE command to the shell. It would be much appreciated if someone could tell me how to do this.

  2. #2
    Registered User dalek's Avatar
    Join Date
    May 2003
    Posts
    135
    You need to look at the System.Diagnostics.Process class..

    You can do something like the following to execute a command in the shell. But I don't think this is going to work for the pause command as it is not a file as such. What are you trying to acheive, perhaps there is a better way of doing this?

    Code:
    System.Diagnostics.Process proc = new System.Diagnostics.Process();
    proc.EnableRaisingEvents=false;
    proc.StartInfo.FileName="calc";
    proc.Start();

  3. #3
    Registered User
    Join Date
    Aug 2004
    Posts
    3
    Well I guess that I could just use Console.ReadLine(); to wait for the user to press enter. I could also write my own code to have the computer wait for the user to press any key so I guess I'll do one of those two things. I also wanted to use it to add some console arguments to an application I wanted to run but I was reading on MSDN and I figured out how to do that with the arguments property of the StartInfo class.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Windows shell commands - multiple files
    By Magos in forum Tech Board
    Replies: 3
    Last Post: 02-28-2006, 01:56 AM
  2. Shell Commands
    By Frantic- in forum C++ Programming
    Replies: 6
    Last Post: 11-12-2005, 11:35 AM
  3. Program to execute shell commands.
    By LiquidLithium in forum C++ Programming
    Replies: 6
    Last Post: 09-01-2004, 12:22 PM
  4. Sending commands over IDE
    By Coherent in forum Windows Programming
    Replies: 0
    Last Post: 10-07-2003, 11:12 AM
  5. Sending commands to port
    By Neha in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 02-28-2002, 02:52 PM