I have a command line process that I would like to call:
process.StartInfo.FileName = "docker";
process.StartInfo.Arguments = "--format='{{(index (index .NetworkSettings.Ports \"5000/tcp\") 0).HostPort}}' " + containerId;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.WorkingDirectory = "./";
process.Start();
process.ErrorDataReceived += new DataReceivedEventHandler(ErrorOutputReceived);
process.OutputDataReceived += new DataReceivedEventHandler(OutputReceived);
process.EnableRaisingEvents = true;
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit(); //this limit might need to be changed
process.ErrorDataReceived -= new DataReceivedEventHandler(ErrorOutputReceived);
process.OutputDataReceived -= new DataReceivedEventHandler(OutputReceived);
Now, if I use the command at the command line, it works. If I call this code, it fails. I have tracked it down to the quotes around "5000/tcp". Dotnet has some fun rules that prevent it from processing this correctly, even though I am escaping them properly. I have tried these rules and they are giving me some problems. Anyone able to tell me what the escaping characters should be?
Here is the link I saw, but it is not working out as they mention: Backslash and quote in command line arguments