Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit15aeda0

Browse files
committed
Fix system.diagnostics.process.standardoutput code snippets
1 parent7eb2f59 commit15aeda0

File tree

9 files changed

+73
-67
lines changed

9 files changed

+73
-67
lines changed

‎snippets/csharp/System.Diagnostics/Process/StandardOutput/stdoutput-async.cs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,31 @@
33

44
publicclassExample
55
{
6-
publicstaticvoidMain()
7-
{
8-
varp=newProcess();
9-
p.StartInfo.UseShellExecute=false;
10-
p.StartInfo.RedirectStandardOutput=true;
11-
stringeOut=null;
12-
p.StartInfo.RedirectStandardError=true;
13-
p.ErrorDataReceived+=newDataReceivedEventHandler((sender,e)=>
14-
{eOut+=e.Data;});
15-
p.StartInfo.FileName="Write500Lines.exe";
16-
p.Start();
6+
publicstaticvoidMain()
7+
{
8+
varp=newProcess();
9+
p.StartInfo.UseShellExecute=false;
10+
p.StartInfo.RedirectStandardOutput=true;
11+
stringeOut=null;
12+
p.StartInfo.RedirectStandardError=true;
13+
p.ErrorDataReceived+=newDataReceivedEventHandler((sender,e)=>
14+
{eOut+=e.Data;});
15+
p.StartInfo.FileName="Write500Lines.exe";
16+
p.Start();
1717

18-
// To avoid deadlocks, use an asynchronous read operation on at least one of the streams.
19-
p.BeginErrorReadLine();
20-
stringoutput=p.StandardOutput.ReadToEnd();
21-
p.WaitForExit();
18+
// To avoid deadlocks, use an asynchronous read operation on at least one of the streams.
19+
p.BeginErrorReadLine();
20+
stringoutput=p.StandardOutput.ReadToEnd();
21+
p.WaitForExit();
2222

23-
Console.WriteLine($"The last 50 characters in the output stream are:\n'{output.Substring(output.Length-50)}'");
24-
Console.WriteLine($"\nError stream:{eOut}");
25-
}
23+
Console.WriteLine($"The last 50 characters in the output stream are:\n'{output.Substring(output.Length-50)}'");
24+
Console.WriteLine($"\nError stream:{eOut}");
25+
}
2626
}
2727
// The example displays the following output:
2828
// The last 50 characters in the output stream are:
29-
// ' 49,800.20%
30-
// Line 500 of 500 written:49,900.20%
29+
// 'ritten: 99,80%
30+
// Line 500 of 500 written:100,00%
3131
// '
3232
//
3333
// Error stream: Successfully wrote 500 lines.

‎snippets/csharp/System.Diagnostics/Process/StandardOutput/stdoutput-sync.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@
33

44
publicclassExample2
55
{
6-
publicstaticvoidMain()
7-
{
8-
varp=newProcess();
9-
p.StartInfo.UseShellExecute=false;
10-
p.StartInfo.RedirectStandardOutput=true;
11-
p.StartInfo.FileName="Write500Lines.exe";
12-
p.Start();
6+
publicstaticvoidMain()
7+
{
8+
varp=newProcess();
9+
p.StartInfo.UseShellExecute=false;
10+
p.StartInfo.RedirectStandardOutput=true;
11+
p.StartInfo.FileName="Write500Lines.exe";
12+
p.Start();
1313

14-
// To avoid deadlocks, always read the output stream first and then wait.
15-
stringoutput=p.StandardOutput.ReadToEnd();
16-
p.WaitForExit();
14+
// To avoid deadlocks, always read the output stream first and then wait.
15+
stringoutput=p.StandardOutput.ReadToEnd();
16+
p.WaitForExit();
1717

18-
Console.WriteLine($"The last 50 characters in the output stream are:\n'{output.Substring(output.Length-50)}'");
19-
}
18+
Console.WriteLine($"The last 50 characters in the output stream are:\n'{output.Substring(output.Length-50)}'");
19+
}
2020
}
2121
// The example displays the following output:
2222
// Successfully wrote 500 lines.
2323
//
2424
// The last 50 characters in the output stream are:
25-
// ' 49,800.20%
26-
// Line 500 of 500 written:49,900.20%
25+
// 'ritten: 99,80%
26+
// Line 500 of 500 written:100,00%
2727
// '
Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
usingSystem;
2-
usingSystem.IO;
32

43
publicclassExample3
54
{
6-
publicstaticvoidMain()
7-
{
8-
for(intctr=0;ctr<500;ctr++)
9-
Console.WriteLine($"Line{ctr+1} of 500 written:{ctr+1/500.0:P2}");
5+
publicstaticvoidMain()
6+
{
7+
for(intctr=0;ctr<500;ctr++)
8+
Console.WriteLine($"Line{ctr+1} of 500 written:{(ctr+1)/500.0:P2}");
109

11-
Console.Error.WriteLine("\nSuccessfully wrote 500 lines.\n");
12-
}
10+
Console.Error.WriteLine("\nSuccessfully wrote 500 lines.\n");
11+
}
1312
}
1413
// The example displays the following output:
15-
// The last 50 characters in the output stream are:
16-
// ' 49,800.20%
17-
// Line 500 of 500 written: 49,900.20%
18-
//'
14+
// Line 1 of 500 written: 0,20%
15+
// Line 2 of 500 written: 0,40%
16+
// Line 3 of 500 written: 0,60%
17+
// ...
18+
// Line 498 of 500 written: 99,60%
19+
// Line 499 of 500 written: 99,80%
20+
// Line 500 of 500 written: 100,00%
1921
//
20-
//Error stream:Successfully wrote 500 lines.
22+
// Successfully wrote 500 lines.

‎snippets/fsharp/System.Diagnostics/Process/StandardOutput/stdoutput-async.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ printfn $"The last 50 characters in the output stream are:\n'{output.Substring(o
2121
printfn $"\nError stream: {eOut}"
2222
// The example displays the following output:
2323
// The last 50 characters in the output stream are:
24-
// ' 49,800.20%
25-
// Line 500 of 500 written:49,900.20%
24+
// 'ritten: 99,80%
25+
// Line 500 of 500 written:100,00%
2626
// '
2727
//
2828
// Error stream: Successfully wrote 500 lines.

‎snippets/fsharp/System.Diagnostics/Process/StandardOutput/stdoutput-sync.fs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ p.WaitForExit()
1515
printfn $"The last 50 characters in the output stream are:\n'{output.Substring(output.Length - 50)}'"
1616
// The example displays the following output:
1717
// Successfully wrote 500 lines.
18-
//
1918
// The last 50 characters in the output stream are:
20-
// ' 49,800.20%
21-
// Line 500 of 500 written:49,900.20%
19+
// 'ritten: 99,80%
20+
// Line 500 of 500 written:100,00%
2221
// '

‎snippets/fsharp/System.Diagnostics/Process/StandardOutput/write500lines.fs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ for i in 1. .. 500. do
55

66
eprintfn "Successfully wrote500 lines.";
77
// The example displays the following output:
8-
// The last 50 characters in the output stream are:
9-
// ' 49,800.20%
10-
// Line 500 of 500 written: 49,900.20%
11-
//'
12-
//
13-
// Error stream: Successfully wrote 500 lines.
8+
// Line 1 of 500 written: 0,20%
9+
// Line 2 of 500 written: 0,40%
10+
// Line 3 of 500 written: 0,60%
11+
// ...
12+
// Line 498 of 500 written: 99,60%
13+
// Line 499 of 500 written: 99,80%
14+
// Line 500 of 500 written: 100,00%
15+
// Successfully wrote 500 lines.

‎snippets/visualbasic/api/system.diagnostics/process/standardoutput/Write500Lines.vb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,19 @@
33
PublicModuleExample
44
PublicSubMain()
55
ForctrAsInteger=0To499
6-
Console.WriteLine($"Line {ctr + 1} of 500 written: {ctr + 1/500.0:P2}")
6+
Console.WriteLine($"Line {ctr + 1} of 500 written: {(ctr + 1) /500.0:P2}")
77
Next
88

99
Console.Error.WriteLine($"{vbCrLf}Successfully wrote 500 lines.{vbCrLf}")
1010
EndSub
1111
EndModule
1212
' The example displays the following output:
13-
' The last 50 characters in the output stream are:
14-
' ' 49,800.20%
15-
' Line 500 of 500 written: 49,900.20%
13+
' Line 1 Of 500 written 0,20%
14+
' Line 2 of 500 written: 0,40%
15+
' Line 3 of 500 written: 0,60%
16+
' ...
17+
' Line 498 of 500 written: 99,60%
18+
' Line 499 of 500 written: 99,80%
19+
' Line 500 of 500 written: 100,00%
1620
'
17-
'
18-
' Error stream: Successfully wrote 500 lines.
21+
' Successfully wrote 500 lines.

‎snippets/visualbasic/api/system.diagnostics/process/standardoutput/stdoutput-async.vb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ Public Module Example
2222
EndModule
2323
' The example displays the following output:
2424
' The last 50 characters in the output stream are:
25-
' ' 49,800.20%
26-
' Line 500 of 500 written:49,900.20%
25+
' 'ritten: 99,80%
26+
' Line 500 of 500 written:100,00%
2727
' '
2828
'
2929
' Error stream: Successfully wrote 500 lines.

‎snippets/visualbasic/api/system.diagnostics/process/standardoutput/stdoutput-sync.vb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ End Module
1919
' Successfully wrote 500 lines.
2020
'
2121
' The last 50 characters in the output stream are:
22-
' ' 49,800.20%
23-
' Line 500 of 500 written:49,900.20%
22+
' 'ritten: 99,80%
23+
' Line 500 of 500 written:100,00%
2424
' '

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp