File tree Expand file tree Collapse file tree 3 files changed +21
-3
lines changed
Expand file tree Collapse file tree 3 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -49,14 +49,17 @@ await foreach (string item in ProcessX.StartAsync("dotnet --info"))
4949}
5050
5151// receive string result from stdout.
52- var branch = await ProcessX .StartAsync (" git branch --show-current " ).FirstAsync ();
52+ var version = await ProcessX .StartAsync (" dotnet --version " ).FirstAsync ();
5353
5454// receive buffered result(similar as WaitForExit).
5555string [] result = await ProcessX .StartAsync (" dotnet --info" ).ToTask ();
5656
5757// like the shell exec, write all data to console.
5858await ProcessX .StartAsync (" dotnet --info" ).WriteLineAllAsync ();
5959
60+ // consume all result and wait complete asynchronously(useful to use no result process).
61+ await ProcessX .StartAsync (" cmd /c mkdir foo" ).WaitAsync ();
62+
6063// when ExitCode is not 0 or StandardError is exists, throws ProcessErrorException
6164try
6265{
@@ -269,6 +272,9 @@ FirstAsync(CancellationToken cancellationToken = default)
269272// return Task<string?>
270273FirstOrDefaultAsync (CancellationToken cancellationToken = default )
271274
275+ // return Task
276+ WaitAsync (CancellationToken cancellationToken = default )
277+
272278// return Task<string[]>
273279ToTask (CancellationToken cancellationToken = default )
274280
Original file line number Diff line number Diff line change 99
1010
1111
12- var s = await ProcessX . StartAsync ( "git branch --show-current" ) . FirstAsync ( ) ;
13- System . Console . WriteLine ( s ) ;
12+ await ProcessX . StartAsync ( "cmd /c mkdir foo" ) . WaitAsync ( ) ;
13+
14+ return ;
15+
1416
1517
1618// `await string` execute process like shell
Original file line number Diff line number Diff line change @@ -24,6 +24,16 @@ public IAsyncEnumerator<string> GetAsyncEnumerator(CancellationToken cancellatio
2424 return new ProcessAsyncEnumerator ( process , channel , cancellationToken ) ;
2525 }
2626
27+ /// <summary>
28+ /// Consume all result and wait complete asynchronously.
29+ /// </summary>
30+ public async Task WaitAsync ( CancellationToken cancellationToken = default )
31+ {
32+ await foreach ( var _ in this . WithCancellation ( cancellationToken ) . ConfigureAwait ( false ) )
33+ {
34+ }
35+ }
36+
2737 /// <summary>
2838 /// Returning first value. If does not return any data, returns empty string.
2939 /// </summary>
You can’t perform that action at this time.
0 commit comments