Process.StandardInput.Write未使用.Net Core写入MacOS上的终端

时间:2018-10-04 03:50:46

标签: mongodb macos .net-core

我正在启动一个具有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();

这是结果 enter image description here

1 个答案:

答案 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");