Reputation: 65
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
Upvotes: 0
Views: 20432
Reputation: 1765
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);
Upvotes: 3