Mongo Shell无法运行

时间:2019-12-11 11:36:01

标签: mongodb cmd .net-core mongo-shell

在cmd中打开文件目录并打开mongo shell没问题 但是,当使用.net core 3.0 console.app执行此过程时,出现如下“ bye”错误

Process cmd = new Process();
cmd.StartInfo.FileName = "cmd.exe ";
cmd.StartInfo.RedirectStandardInput = true;
cmd.StartInfo.RedirectStandardOutput = true;
cmd.StartInfo.CreateNoWindow = true;
cmd.StartInfo.UseShellExecute = false;
cmd.Start();
/* execute "dir" */
cmd.StandardInput.WriteLine("cd ..");
cmd.StandardInput.WriteLine("cd ..");
cmd.StandardInput.WriteLine("cd ..");
cmd.StandardInput.WriteLine("cd ..");
cmd.StandardInput.WriteLine("cd ..");
cmd.StandardInput.WriteLine("cd ..");
cmd.StandardInput.WriteLine("cd ..");

cmd.StandardInput.WriteLine("cd C:\\Program Files\\MongoDB\\Server\\4.2\\bin");
cmd.StandardInput.WriteLine("mongo");


cmd.StandardInput.Flush();

cmd.StandardInput.Close();

Console.WriteLine(cmd.StandardOutput.ReadToEnd());

0 个答案:

没有答案