0

i am trying to run the following cmd command, that works on the CMD, from a C# console app but nothing happens:

      string strCmdText = "\\office\\Public\\Tools\\myTool\\myTool_V1.0\\myTool.exe -kan tools -kdb Adhoc - ktn Components3 - uri https://coprime.osdinfra.net";
      System.Diagnostics.Process.Start("CMD.exe", strCmdText);

the cmd window is emmidiatly closed after pressing F5 in VS so i can't see the output of "myTool.exe" - which does in fact print status about its progress on the cmd when run from a cmd window.

Also the desired effect of the program doesn't happen so i know it didn't work.

Need help please

4
  • You are opening a command prompt window from a console app? Why? Commented Apr 21, 2016 at 17:44
  • 2
    possible duplicate of stackoverflow.com/questions/21295494/… Commented Apr 21, 2016 at 17:45
  • cmd likely isn't necessary to run an .exe, but as long as you are using cmd, it requires an option flag – cmd /C \path\to\app.exe. Commented Apr 21, 2016 at 17:47
  • How many times do I have to say this. SPECIFY FULL PATHS and stop relying on default directories that you aren't controlling. Commented Apr 21, 2016 at 21:40

1 Answer 1

3

Command Prompt does not take a program in as an argument to start. However, I can't see a reason to use command prompt here. You're code is starting the process "Cmd.exe" so it can start another process. Why not eliminate the middle man and just start the process you want to start? Then you can pass the process' real arguments as arguments in process.start().

Update:

You can start a program from command prompt, but it's a specific command. It goes like this:

CMD.exe /c {string of commands to execute}

So for instance, you could run it through cmd if you need to by doing this:

  string strCmdText = "/c start \\office\\Public\\Tools\\myTool\\myTool_V1.0\\myTool.exe -kan tools -kdb Adhoc - ktn Components3 - uri https://coprime.osdinfra.net";
  System.Diagnostics.Process.Start("CMD.exe", strCmdText);
Sign up to request clarification or add additional context in comments.

2 Comments

Is the "start" keyword necessary, and is the /c supposed to be capital C or not?
I found without the start keyword it didn't work. i believe it's a lowercase c

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.