@@ -56,8 +56,19 @@ public static (bool success, string output) ExecuteCommand(string exeName, strin
56
56
UseShellExecute = false ,
57
57
RedirectStandardOutput = true ,
58
58
} ;
59
+ return ExecuteCommand ( processStartInfo ) ;
60
+ }
61
+
62
+ /// <inheritdoc cref="ExecuteCommand(string,string,string)"/>
63
+ public static ( bool success , string output ) ExecuteCommand ( ProcessStartInfo processStartInfo )
64
+ {
59
65
var process = Process . Start ( processStartInfo ) ;
60
66
67
+ if ( process is null )
68
+ {
69
+ return ( false , "Process.Start return null." ) ;
70
+ }
71
+
61
72
var output = process . StandardOutput . ReadToEnd ( ) ;
62
73
bool success = true ;
63
74
if ( process . HasExited )
@@ -68,20 +79,17 @@ public static (bool success, string output) ExecuteCommand(string exeName, strin
68
79
return ( success , output ) ;
69
80
}
70
81
82
+ /// <inheritdoc cref="ExecuteCommand(string,string,string)"/>
71
83
public static async Task < string > ExecuteCommandAsync ( string exeName , string arguments )
72
84
{
73
85
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 )
76
88
{
77
- task . Wait ( TimeSpan . FromMinutes ( 1 ) ) ;
78
- if ( task . IsCompleted )
79
- {
80
- return task . Result . output ;
81
- }
89
+ return task . Result . output ;
90
+ }
82
91
83
- return "" ;
84
- } ) ;
92
+ return "" ;
85
93
}
86
94
}
87
95
}
0 commit comments