@@ -107,26 +107,40 @@ public static String getPropertyOrEnvironmentVariable(String name) {
107
107
}
108
108
109
109
public static boolean runProcessAndWait (String exec , String params ) throws IOException , InterruptedException {
110
- return runProcessAndGetExitCode (exec , params ) == 0 ;
110
+ return runProcessAndWait (exec , params , null );
111
+ }
112
+
113
+ public static boolean runProcessAndWait (String exec , String params , String workingDirPath ) throws IOException , InterruptedException {
114
+ return runProcessAndGetExitCode (exec , params , workingDirPath ) == 0 ;
111
115
}
112
116
113
117
public static int runProcessAndGetExitCode (String exec , String params ) throws IOException , InterruptedException {
114
- Process p = runProcess (exec , params );
118
+ return runProcessAndGetExitCode (exec , params , null );
119
+ }
120
+
121
+ public static int runProcessAndGetExitCode (String exec , String params , String workingDirPath ) throws IOException , InterruptedException {
122
+ Process p = runProcess (exec , params , workingDirPath );
115
123
System .out .println (getProcessOutput (p ));
116
124
return p .waitFor ();
117
125
}
118
126
119
127
public static String runProcessAndGetOutput (String command , String params ) throws IOException {
120
- return getProcessOutput (runProcess (command , params ));
128
+ return getProcessOutput (runProcess (command , params , null ));
121
129
}
122
130
123
131
public static StringBuilder runProcessAndCollectErrors (String execPath , String params ) throws IOException {
124
- return printProcessErrorsOutput (runProcess (execPath , params ));
132
+ return printProcessErrorsOutput (runProcess (execPath , params , null ));
125
133
}
126
134
127
- static Process runProcess (String execPath , String params ) throws IOException {
135
+ static Process runProcess (String execPath , String params , String workingDirPath ) throws IOException {
128
136
List <String > cmdList = prepareProcessArguments (execPath , params );
129
- return Runtime .getRuntime ().exec (cmdList .toArray (new String [cmdList .size ()]));
137
+ String [] cmdArray = cmdList .toArray (new String [cmdList .size ()]);
138
+ if (workingDirPath != null ) {
139
+ File workingDir = new File (workingDirPath );
140
+ return Runtime .getRuntime ().exec (cmdArray , null , workingDir );
141
+ } else {
142
+ return Runtime .getRuntime ().exec (cmdArray );
143
+ }
130
144
}
131
145
132
146
static List <String > prepareProcessArguments (String exec , String params ) {
0 commit comments