I trying to run the following command in cmd.exe by c# code.
- mkdir myfolder
- cd myfolder
- git init
- git remote set-url origin https://gitlab.company.com/testgroup/server.git
- git fetch --dry-run
- cd ..
- rmdir myfolder
I don't know how to pass all the arguments in single Process.Start();
. After run the 4th command I will take the output string
and do some operation with that string
.
I tried like this
const string strCmdText = "/C mkdir myfolder& cd myfolder& git init & git remote set-url origin https://gitlab.company.com/project.git & git fetch --dry-run & cd .. & rmdir myfolder";
Process.Start("CMD.exe", strCmdText);
Above command works properly. But I do not know how to get the execution text from cmd.exe
. The text which I want is shown in below image.
I used below code to get the output string
. But at the line of reading the output(string output = cmd.StandardOutput.ReadToEnd();
), the execution stopped. I means it will not go to next line also it will not terminate the program. Simply show the lack screen.
Process cmd = new Process();
cmd.StartInfo.FileName = "cmd.exe";
cmd.StartInfo.Arguments = "/C mkdir myfolder& cd myfolder& git init & git remote set-url origin https://gitlab.company.com/project.git & git fetch --dry-run & cd .. & rmdir myfolder";
cmd.StartInfo.UseShellExecute = false;
cmd.StartInfo.RedirectStandardOutput = true;
cmd.StartInfo.RedirectStandardError = true;
cmd.Start();
string output = cmd.StandardOutput.ReadToEnd();
Console.WriteLine(output);
How do I get the output string
?