public CommandHub(IHubContext <CommandHub> hub) { if (_hub == null) { _hub = hub; //Process로 하면 OutputDataReceived 이벤트 발생기준이 NewLine 이라서 마지막줄을 못가져옴 //Stackoverflow 에서 커스텀 버전을 봄 //https://stackoverflow.com/questions/1033648/c-sharp-redirect-console-application-output-how-to-flush-the-output if (cmdProcess == null) { cmdProcess = new FixedProcess(); cmdProcess.StartInfo.FileName = "cmd"; cmdProcess.StartInfo.UseShellExecute = false; cmdProcess.StartInfo.CreateNoWindow = true; cmdProcess.StartInfo.RedirectStandardOutput = true; cmdProcess.StartInfo.RedirectStandardInput = true; cmdProcess.OutputDataReceived += CmdProcess_OutputDataReceived; //cmdProcess.EnableRaisingEvents = true; //cmdProcess.Exited += CmdProcess_Exited; cmdProcess.Start(); cmdStreamWriter = cmdProcess.StandardInput; cmdProcess.BeginOutputReadLine(); } } }
static string ConvertPath(string arg) { arg = "'" + arg.Replace("'", "'\\''") + "'"; var processStartInfo = new ProcessStartInfo { FileName = @"c:\windows\system32\cmd.exe", Arguments = "/c c:\\windows\\system32\\wsl.exe " + wslpath + " " + arg, UseShellExecute = false, RedirectStandardOutput = true, }; var p = new FixedProcess(); p.StartInfo = processStartInfo; p.EnableRaisingEvents = true; p.Start(); string output = p.StandardOutput.ReadToEnd(); p.WaitForExit(); return(output.Replace("\n", "")); }