• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 239
  • Last Modified:

executing command line

How do I execute a command line statement in C#?
1 Solution
Use this helper method:

using System.Diagnostics;
public static void ExecThroughCmdShell(string command) {

    " /c " + command

The name of the command interpreter is in the COMSPEC env variable (usually something like c:\windows\system32\cmd.exe). You can give cmd.exe a /c param to make it run the rest of the command line and then exit. You can call the method like ExecThroughCmdShell("dir /s /p c:\\windows").
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.

Join & Write a Comment

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now