Please could someone advise how I can escape an '&' character in a string when trying to start a process like the following:
var arguments = $"/C \"C:\\Here & Here\\MyExe.exe\"";
Process process = new Process
{
StartInfo =
{
Arguments = arguments,
FileName = "cmd.exe",
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden,
UseShellExecute = false
}
};
process.Start();
I need to execute the process using cmd.exe /C I've tried replacing the string with to use a ^& like this:
var arguments = $"/C \"C:\\Here ^& Here\\MyExe.exe\"";
but it still doesn't find the path.
In a cmd window i would just do cmd.exe /C ""C:\Here ^& Here\MyExe.exe"" and it works just not via a process start
Thanks
&in the cmd instance or the C# instance or both? What is the literal path of the file.var arguments = @"/C ""C:\Here ^& Here\MyExe.exe""";&try putting the*wildcard character and see if it works. So it would bevar arguments = $"/C \"C:\\Here *\\MyExe.exe\"";