@@ -46,46 +46,65 @@ public virtual void Run(Logger logger, Action end)
4646 CreateNoWindow = CreateNoWindow ,
4747 WorkingDirectory = WorkingDirectory ,
4848 RedirectStandardError = RedirectStandardError ,
49- RedirectStandardOutput = RedirectStandardOutput
49+ RedirectStandardOutput = RedirectStandardOutput ,
50+ StandardErrorEncoding = RedirectStandardError ? Encoding . UTF8 : null ,
51+ StandardOutputEncoding = RedirectStandardOutput ? Encoding . UTF8 : null ,
5052 }
5153 } ;
5254 LSTGInstance . EnableRaisingEvents = true ;
53- LSTGInstance . Start ( ) ;
54-
55- logger ( "LuaSTG is Running.\n \n " ) ;
56-
57- LSTGInstance . Exited += ( s , e ) => {
58- FileStream fs = null ;
59- StreamReader sr = null ;
60- StringBuilder sb = new StringBuilder ( ) ;
61- try
55+
56+ if ( RedirectStandardOutput )
57+ {
58+ LSTGInstance . OutputDataReceived += ( s , e ) => logger ( e . Data ) ;
59+ LSTGInstance . Exited += ( s , e ) =>
6260 {
63- fs = new FileStream ( Path . GetFullPath ( Path . Combine (
64- Path . GetDirectoryName ( LuaSTGPath ) , LogFileName ) ) , FileMode . Open ) ;
65- sr = new StreamReader ( fs ) ;
66- int i = 0 ;
67- while ( ! sr . EndOfStream && i < 8192 )
61+ end ( ) ;
62+ logger ( "\n Exited with code " + LSTGInstance . ExitCode + "." ) ;
63+ } ;
64+ }
65+ else
66+ {
67+ LSTGInstance . Exited += ( s , e ) => {
68+ FileStream fs = null ;
69+ StreamReader sr = null ;
70+ StringBuilder sb = new StringBuilder ( ) ;
71+ try
72+ {
73+ fs = new FileStream ( Path . GetFullPath ( Path . Combine (
74+ Path . GetDirectoryName ( LuaSTGPath ) , LogFileName ) ) , FileMode . Open ) ;
75+ sr = new StreamReader ( fs ) ;
76+ int i = 0 ;
77+ while ( ! sr . EndOfStream && i < 8192 )
78+ {
79+ sb . Append ( sr . ReadLine ( ) ) ;
80+ sb . Append ( "\n " ) ;
81+ i ++ ;
82+ }
83+ logger ( sb . ToString ( ) ) ;
84+ end ( ) ;
85+ }
86+ catch ( System . Exception exc )
87+ {
88+ System . Windows . MessageBox . Show ( exc . ToString ( ) ) ;
89+ }
90+ finally
6891 {
69- sb . Append ( sr . ReadLine ( ) ) ;
70- sb . Append ( "\n " ) ;
71- i ++ ;
92+ if ( fs != null ) fs . Close ( ) ;
93+ if ( sr != null ) sr . Close ( ) ;
7294 }
95+ sb . Append ( "\n Exited with code " + LSTGInstance . ExitCode + "." ) ;
7396 logger ( sb . ToString ( ) ) ;
74- end ( ) ;
75- }
76- catch ( System . Exception exc )
77- {
78- System . Windows . MessageBox . Show ( exc . ToString ( ) ) ;
79- }
80- finally
81- {
82- if ( fs != null ) fs . Close ( ) ;
83- if ( sr != null ) sr . Close ( ) ;
84- }
85- sb . Append ( "\n Exited with code " + LSTGInstance . ExitCode + "." ) ;
86- logger ( sb . ToString ( ) ) ;
87- } ;
97+ } ;
98+ }
8899
100+ LSTGInstance . Start ( ) ;
101+
102+ logger ( "LuaSTG is Running.\n \n " ) ;
103+
104+ if ( RedirectStandardOutput )
105+ {
106+ LSTGInstance . BeginOutputReadLine ( ) ;
107+ }
89108 }
90109 else
91110 {
0 commit comments