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

scifie
  • 65
  • 1
  • 2
  • 14
  • You are opening a command prompt window from a console app? Why? – stackErr Apr 21 '16 at 17:44
  • 2
    possible duplicate of http://stackoverflow.com/questions/21295494/running-dos-command-line-from-c – rashfmnb Apr 21 '16 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`. – Jonathan Lonowski Apr 21 '16 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. –  Apr 21 '16 at 21:40

1 Answers1

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);
oppassum
  • 1,746
  • 13
  • 22