Home > Enterprise >  c# problem with a specific CMD Command Line
c# problem with a specific CMD Command Line

Time:12-25

I'm having a hard time with executing a CMD command line in C# (when I copy the command to CMD it works).

The command(the quotation marks is part of the command):

"C:\Program Files (x86)\SolarWinds\Dameware Remote Support\dwrcc.exe" -c: -h: -m:10.10.41.82 -a:1

How I wrote it C#:

System.Diagnostics.Process.Start("\"C:\\Program Files (x86)\\SolarWinds\\Dameware Remote Support\\dwrcc.exe\" -c: -h: -m:10.10.41.82 -a:1");

The Error I get is that the location has not been found. there is some issue with the brackets or quotation marks I think, but I don't know what.

CodePudding user response:

Try writing it with @ instead

System.Diagnostics.Process.Start(@"C:\Program Files (x86)\SolarWinds\Dameware Remote Support\dwrcc.exe", "-c: -h: -m:10.10.41.82 -a:1");

Prefixing the string with @ indicates that it should be treated as a literal, i.e. no escaping.

So, you can for example if your string contains a path you would typically do this:

string path = "c:\\path\\to\\file.txt";

Writing it with @ allows you to write it clearer without needing the double slashes

string path = @"c:\path\to\file.txt";

CodePudding user response:

You can escape Unicode characters by preceding the hexadecimal value with "\u". The hexadecimal value of a double quote is 0022, so you can include this in your string.

For example:

quote = "\u0022Alive\u0022, she cried!";

  • Related