0

I am using Process and ProcessStartInfo to execute Docker commands. However, it doesn't work for some commands. Here is the code and the example commands that I am using. All these commands work fine when executed on the Docker Toolbox command line.

Commands:

  1. string command = "docker-machine create -d virtualbox --virtualbox-memory 4096 devmachine"
  2. string command = "docker-machine ip devmachine"
  3. string command = "eval $(docker-machine env devmachine)"

    ProcessStartInfo psi = new ProcessStartInfo();
    psi.CreateNoWindow = true;
    psi.FileName = @"C:\Program Files\Git\bin\bash.exe";
    psi.WorkingDirectory = @"C:\Program Files\Docker Toolbox";
    psi.Arguments = @"--login -i ""C:\Program Files\Docker Toolbox\start.sh"" " + command;
    psi.UseShellExecute = false;
    psi.RedirectStandardOutput = true;
    psi.RedirectStandardInput = true;
    psi.RedirectStandardError = true;
    Process process = Process.Start(psi);
    

Only the 3rd command is not working, the 1st and 2nd works fine. I am wondering if there are strings that need to be escaped for the 3rd command. Only the 3rd command has the $, ( and ) characters

Steve
  • 213,761
  • 22
  • 232
  • 286
jmc
  • 1,649
  • 6
  • 26
  • 47
  • which version of .NET and VS are you using ? – Vignesh.N Oct 12 '16 at 09:04
  • @Vignesh.N .NET 4.5.2, VS 2015 – jmc Oct 12 '16 at 09:04
  • can you try adding @ before your string like `string command = @"eval $(docker-machine env devmachine)"` – Vignesh.N Oct 12 '16 at 09:05
  • @Vignesh.N still does not work. as far as I know `@` escapes `/` backslashes. I'm really not sure about `$` and parentheses – jmc Oct 12 '16 at 09:13
  • prefixing `@` indicated a verbatim string, it does not escape anything and includes everything between the `"` and `";` as part of the string. exception being `"` itself. What is the error you are getting ? – Vignesh.N Oct 12 '16 at 09:17
  • can you try this `string command = @"eval ""$(docker-machine env devmachine)""";` – Vignesh.N Oct 12 '16 at 09:36
  • @Vignesh.N I have tried this also, enclosing the `$(docker-machine env devmachine)` within quotes. I don't have any error whatsoever. If I have, I'll be able to catch them with the `RedirectStandardError`. I'm really thinking that the command may have been changed somewhere before it reaches the Docker Toolbox bash – jmc Oct 12 '16 at 09:57
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/125487/discussion-between-vignesh-n-and-jmc). – Vignesh.N Oct 12 '16 at 10:07

0 Answers0