@@ -56,8 +56,19 @@ public static (bool success, string output) ExecuteCommand(string exeName, strin
5656 UseShellExecute = false ,
5757 RedirectStandardOutput = true ,
5858 } ;
59+ return ExecuteCommand ( processStartInfo ) ;
60+ }
61+
62+ /// <inheritdoc cref="ExecuteCommand(string,string,string)"/>
63+ public static ( bool success , string output ) ExecuteCommand ( ProcessStartInfo processStartInfo )
64+ {
5965 var process = Process . Start ( processStartInfo ) ;
6066
67+ if ( process is null )
68+ {
69+ return ( false , "Process.Start return null." ) ;
70+ }
71+
6172 var output = process . StandardOutput . ReadToEnd ( ) ;
6273 bool success = true ;
6374 if ( process . HasExited )
@@ -68,20 +79,17 @@ public static (bool success, string output) ExecuteCommand(string exeName, strin
6879 return ( success , output ) ;
6980 }
7081
82+ /// <inheritdoc cref="ExecuteCommand(string,string,string)"/>
7183 public static async Task < string > ExecuteCommandAsync ( string exeName , string arguments )
7284 {
7385 var task = Task . Run ( ( ) => ExecuteCommand ( exeName , arguments ) ) ;
74-
75- return await Task . Run ( ( ) =>
86+ await Task . WhenAny ( task , Task . Delay ( TimeSpan . FromMinutes ( 1 ) ) ) ;
87+ if ( task . IsCompleted )
7688 {
77- task . Wait ( TimeSpan . FromMinutes ( 1 ) ) ;
78- if ( task . IsCompleted )
79- {
80- return task . Result . output ;
81- }
89+ return task . Result . output ;
90+ }
8291
83- return "" ;
84- } ) ;
92+ return "" ;
8593 }
8694 }
8795}
0 commit comments