Skip to content

Commit 0209b3d

Browse files
committed
zx returns right string result(without newline)
1 parent 125d9d1 commit 0209b3d

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

sandbox/ConsoleApp/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
using Zx;
99
using static Zx.Env;
1010

11-
11+
var version = await "dotnet --version";
1212

1313

1414
// `await string` execute process like shell

src/ProcessX/ProcessAsyncEnumerable.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ public async Task<string> FirstAsync(CancellationToken cancellationToken = defau
4141
string? data = null;
4242
await foreach (var item in this.WithCancellation(cancellationToken).ConfigureAwait(false))
4343
{
44-
data = (item ?? "");
44+
if (data == null)
45+
{
46+
data = (item ?? "");
47+
}
4548
}
4649

4750
if (data == null)
@@ -62,7 +65,10 @@ public async Task<string> FirstAsync(CancellationToken cancellationToken = defau
6265
string? data = null;
6366
await foreach (var item in this.WithCancellation(cancellationToken).ConfigureAwait(false))
6467
{
65-
data = (item ?? "");
68+
if (data == null)
69+
{
70+
data = (item ?? "");
71+
}
6672
}
6773
return data;
6874
}

src/ProcessX/Zx/Env.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,19 @@ public static IDisposable color(ConsoleColor color)
198198

199199
var runStdout = Task.Run(async () =>
200200
{
201+
var isFirst = true;
201202
await foreach (var item in stdout.WithCancellation(cancellationToken).ConfigureAwait(false))
202203
{
203-
sbOut.AppendLine(item);
204+
if (!isFirst)
205+
{
206+
sbOut.AppendLine();
207+
}
208+
else
209+
{
210+
isFirst = false;
211+
}
212+
213+
sbOut.Append(item);
204214

205215
if (verbose && !forceSilcent)
206216
{
@@ -211,9 +221,18 @@ public static IDisposable color(ConsoleColor color)
211221

212222
var runStdError = Task.Run(async () =>
213223
{
224+
var isFirst = true;
214225
await foreach (var item in stderror.WithCancellation(cancellationToken).ConfigureAwait(false))
215226
{
216-
sbError.AppendLine(item);
227+
if (!isFirst)
228+
{
229+
sbOut.AppendLine();
230+
}
231+
else
232+
{
233+
isFirst = false;
234+
}
235+
sbError.Append(item);
217236

218237
if (verbose && !forceSilcent)
219238
{

0 commit comments

Comments
 (0)