@@ -16,22 +16,22 @@ static class Clipboard
16
16
// This is useful for testing in CI as well.
17
17
private static string _internalClipboard ;
18
18
19
- private static string StartProcess (
20
- string tool ,
21
- string args ,
22
- string stdin = ""
23
- )
19
+ private static string StartProcess ( bool collectOutput , string tool , string args , string stdin = null )
24
20
{
25
- ProcessStartInfo startInfo = new ProcessStartInfo ( ) ;
26
- startInfo . UseShellExecute = false ;
27
- startInfo . RedirectStandardInput = true ;
28
- startInfo . RedirectStandardOutput = true ;
29
- startInfo . RedirectStandardError = true ;
30
- startInfo . FileName = tool ;
31
- startInfo . Arguments = args ;
32
21
string stdout ;
22
+ bool redirectInput = ! string . IsNullOrEmpty ( stdin ) ;
33
23
34
- using ( Process process = new Process ( ) )
24
+ ProcessStartInfo startInfo = new ( )
25
+ {
26
+ UseShellExecute = false ,
27
+ RedirectStandardInput = redirectInput ,
28
+ RedirectStandardOutput = true ,
29
+ RedirectStandardError = true ,
30
+ FileName = tool ,
31
+ Arguments = args
32
+ } ;
33
+
34
+ using ( Process process = new ( ) )
35
35
{
36
36
process . StartInfo = startInfo ;
37
37
try
@@ -42,15 +42,16 @@ private static string StartProcess(
42
42
{
43
43
_clipboardSupported = false ;
44
44
PSConsoleReadLine . Ding ( ) ;
45
- return "" ;
45
+ return string . Empty ;
46
46
}
47
47
48
- if ( stdin != "" )
48
+ if ( redirectInput )
49
49
{
50
50
process . StandardInput . Write ( stdin ) ;
51
51
process . StandardInput . Close ( ) ;
52
52
}
53
- stdout = process . StandardOutput . ReadToEnd ( ) ;
53
+
54
+ stdout = collectOutput ? process . StandardOutput . ReadToEnd ( ) : string . Empty ;
54
55
process . WaitForExit ( 250 ) ;
55
56
56
57
_clipboardSupported = process . ExitCode == 0 ;
@@ -91,7 +92,7 @@ public static string GetText()
91
92
return "" ;
92
93
}
93
94
94
- return StartProcess ( tool , args ) ;
95
+ return StartProcess ( collectOutput : true , tool , args ) ;
95
96
}
96
97
97
98
public static void SetText ( string text )
@@ -128,7 +129,7 @@ public static void SetText(string text)
128
129
return ;
129
130
}
130
131
131
- StartProcess ( tool , args , text ) ;
132
+ StartProcess ( collectOutput : false , tool , args , text ) ;
132
133
if ( _clipboardSupported == false )
133
134
{
134
135
_internalClipboard = text ;
0 commit comments