@@ -14,22 +14,46 @@ private void ConsoleWriteLine(string line)
1414 } ) ;
1515 }
1616
17- public async Task SpawnProc ( string proc , string args )
17+
18+ public async Task SpawnProc ( string proc , string args , bool sync = false )
1819 {
1920 using Process ? p2 = new Process ( ) ;
2021 p2 . StartInfo . FileName = proc ;
2122 p2 . StartInfo . Arguments = args ;
2223 p2 . StartInfo . RedirectStandardOutput = true ;
24+ if ( sync )
25+ {
26+ p2 . StartInfo . RedirectStandardInput = true ;
27+ }
2328 p2 . StartInfo . CreateNoWindow = true ;
2429 p2 . StartInfo . UseShellExecute = false ;
2530 p2 . EnableRaisingEvents = true ;
26- p2 . OutputDataReceived += ( object sender , DataReceivedEventArgs args ) =>
31+ if ( ! sync )
2732 {
28- ConsoleWriteLine ( " " + args . Data ) ;
29- } ;
33+ p2 . OutputDataReceived += ( object sender , DataReceivedEventArgs args ) =>
34+ {
35+ ConsoleWriteLine ( " " + args . Data ) ;
36+ } ;
37+ }
3038 p2 . Start ( ) ;
31- p2 . BeginOutputReadLine ( ) ;
32- await p2 . WaitForExitAsync ( ) ;
39+ if ( ! sync )
40+ {
41+ p2 . BeginOutputReadLine ( ) ;
42+ }
43+ if ( sync )
44+ {
45+ string outp = p2 . StandardOutput . ReadToEnd ( ) ;
46+ ConsoleWriteLine ( outp ) ; // force read console.
47+ if ( outp . Contains ( "Press any key to exit..." ) ) // Hardcoded for only sync proc.
48+ {
49+ mainWindowRef . GeneralError = true ;
50+ }
51+ p2 . WaitForExit ( ) ;
52+ }
53+ else
54+ {
55+ await p2 . WaitForExitAsync ( ) ;
56+ }
3357 }
3458 public async Task ProcMon ( string processName )
3559 {
0 commit comments