How to execute command line (CMD) commands from a C# program?
Hello everyone! I'm a beginner in C# and writing a small application for task automation. I need the program to be able to execute Windows command line commands, for example, copy files using `copy`, run `ping`, or execute `ipconfig`. I know you can just open CMD and enter commands manually, but I want everything to be done automatically from code.\n\nI tried using `Process.Start("cmd.exe", "/c ping google.com")`, but nothing happens — the command prompt window flashes and immediately closes, and I don't see the result. How do I pass a command, wait for it to complete, and get the output (for example, whether the command executed successfully or the text from the console)?\n\nHere's my current code that doesn't work:\n\n```csharp\nProcess.Start("cmd.exe", "/c ping google.com");\n```\n\nI've heard about `P
No answers yet.
Log in to leave an answer