Reputation: 13
Trying to send the code below to the command line, but I get errors. I know there is an issue with backslashes sent to CMD. Any help here on how to send it? Thanks!
string strCmdText="/C C:\\Program Files\\MetaTrader 5\\terminal64.exe /config:C:\\Users\\vguer036\\AppData\\Roaming\\MetaQuotes\\Terminal\\D0E8209F77C8CF37AD8BF550E51FF075\\config\\common.ini";
System.Diagnostics.Process.Start("CMD.exe", strCmdText);
Upvotes: 1
Views: 902
Reputation: 39338
When you use this:
string strCmdText="/C C:\\Program Files\\MetaTrader 5\\terminal64.exe /config:C:\\Users\\vguer036\\AppData\\Roaming\\MetaQuotes\\Terminal\\D0E8209F77C8CF37AD8BF550E51FF075\\config\\common.ini";
System.Diagnostics.Process.Start("CMD.exe", strCmdText);
then you are trying to start the application CMD.exe, which in turn you instruct to execute a particular application. However, because of the spaces, what CMD is trying to execute is the command C:\\Program
with parameters Files\\MetaTrader
, 5\\terminal64.exe
etc. That is where your error message comes from.
One way to solve this is to add extra quotes around the filename (as Dour High Arch commented):
string strCmdText=@"/C ""C:\Program Files\MetaTrader 5\terminal64.exe"" ""/config:C:\Users\vguer036\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075\config\common.ini""";
Note the doubled quotes, which are required to use a literal quote inside a verbatim string literal (@"..."
).
But this way you are still executing one application (CMD.exe) to start another (terminal64.exe). Why not start that terminal64 directly?
System.Diagnostics.Process.Start(
@"C:\Program Files\MetaTrader 5\terminal64.exe",
@"/config:C:\Users\vguer036\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075\config\common.ini");
You should experiment to see whether you need extra quotes around that application name, but I don't think so.
Upvotes: 1