@@ -93,13 +93,21 @@ public static String GetEnvironmentVariable(String name) {
93
93
}
94
94
95
95
public static bool RunProcessAndWait ( String exec , String @params ) {
96
- return RunProcessAndGetExitCode ( exec , @params ) == 0 ;
96
+ return RunProcessAndWait ( exec , @params , null ) ;
97
97
}
98
98
99
- public static int RunProcessAndGetExitCode ( String exec , String @params ) {
100
- using ( Process proc = new Process ( ) )
101
- {
102
- SetProcessStartInfo ( proc , exec , @params ) ;
99
+ public static bool RunProcessAndWait ( String exec , String @params , String workingDirPath ) {
100
+ return RunProcessAndGetExitCode ( exec , @params , workingDirPath ) == 0 ;
101
+ }
102
+
103
+ public static int RunProcessAndGetExitCode ( String exec , String @params )
104
+ {
105
+ return RunProcessAndGetExitCode ( exec , @params , null ) ;
106
+ }
107
+
108
+ public static int RunProcessAndGetExitCode ( String exec , String @params , String workingDirPath ) {
109
+ using ( Process proc = new Process ( ) ) {
110
+ SetProcessStartInfo ( proc , exec , @params , workingDirPath ) ;
103
111
proc . Start ( ) ;
104
112
Console . WriteLine ( GetProcessOutput ( proc ) ) ;
105
113
proc . WaitForExit ( ) ;
@@ -109,9 +117,8 @@ public static int RunProcessAndGetExitCode(String exec, String @params) {
109
117
110
118
public static String RunProcessAndGetOutput ( String exec , String @params ) {
111
119
String processOutput ;
112
- using ( Process proc = new Process ( ) )
113
- {
114
- SetProcessStartInfo ( proc , exec , @params ) ;
120
+ using ( Process proc = new Process ( ) ) {
121
+ SetProcessStartInfo ( proc , exec , @params , null ) ;
115
122
proc . Start ( ) ;
116
123
processOutput = GetProcessOutput ( proc ) ;
117
124
proc . WaitForExit ( ) ;
@@ -122,9 +129,8 @@ public static String RunProcessAndGetOutput(String exec, String @params) {
122
129
123
130
public static StringBuilder RunProcessAndCollectErrors ( String exec , String @params ) {
124
131
StringBuilder errorsBuilder ;
125
- using ( Process proc = new Process ( ) )
126
- {
127
- SetProcessStartInfo ( proc , exec , @params ) ;
132
+ using ( Process proc = new Process ( ) ) {
133
+ SetProcessStartInfo ( proc , exec , @params , null ) ;
128
134
proc . Start ( ) ;
129
135
errorsBuilder = GetProcessErrorsOutput ( proc ) ;
130
136
Console . Out . WriteLine ( errorsBuilder . ToString ( ) ) ;
@@ -135,12 +141,17 @@ public static StringBuilder RunProcessAndCollectErrors(String exec, String @para
135
141
}
136
142
137
143
internal static void SetProcessStartInfo ( Process proc , String exec , String @params ) {
144
+ SetProcessStartInfo ( proc , exec , @params , null ) ;
145
+ }
146
+
147
+ internal static void SetProcessStartInfo ( Process proc , String exec , String @params , String workingDir ) {
138
148
String [ ] processArguments = PrepareProcessArguments ( exec , @params ) ;
139
149
proc . StartInfo = new ProcessStartInfo ( processArguments [ 0 ] , processArguments [ 1 ] ) ;
140
150
proc . StartInfo . UseShellExecute = false ;
141
151
proc . StartInfo . RedirectStandardOutput = true ;
142
152
proc . StartInfo . RedirectStandardError = true ;
143
153
proc . StartInfo . CreateNoWindow = true ;
154
+ proc . StartInfo . WorkingDirectory = workingDir ;
144
155
}
145
156
146
157
internal static String [ ] PrepareProcessArguments ( String exec , String @params ) {
0 commit comments