我正在启动一个具有Mongo shell连接的终端,并发送“ show dbs”命令。但是似乎在终端连接后它不接受任何命令。我已经在Windows 10和Ubuntu上做到了这一点,但没有问题,但MacOSX High Sierra不想表现出色。
我正在使用的代码。
var scriptFile = "/Users/donny/Downloads/CMStudio/mongo/mongo_script.sh";
var appPath = "/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal";
var process = new Process();
process.StartInfo.UseShellExecute = false;
process.StartInfo.FileName = appPath;
process.StartInfo.Arguments = scriptFile;
process.StartInfo.RedirectStandardInput = true;
process.Start();
process.StandardInput.Write("show dbs\n");
process.StandardInput.Flush();
答案 0 :(得分:0)
尝试一下:
var scriptFile = "/Users/donny/Downloads/CMStudio/mongo/mongo_script.sh";
var appPath = "/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal";
var process = new Process();
process.StartInfo.UseShellExecute = false;
process.StartInfo.FileName = appPath;
process.StartInfo.Arguments = scriptFile;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.Start();
proc.BeginOutputReadLine();
proc.BeginErrorReadLine();
process.StandardInput.WriteLine("show dbs\n");