MCPcopy Create free account
hub / github.com/apache/pig / processShCommand

Method processShCommand

src/org/apache/pig/tools/grunt/GruntParser.java:1189–1248  ·  view source on GitHub ↗
(String[] cmdTokens)

Source from the content-addressed store, hash-verified

1187 }
1188
1189 @Override
1190 protected void processShCommand(String[] cmdTokens) throws IOException {
1191 filter.validate(PigCommandFilter.Command.SH);
1192 for (int i = 0 ; i < cmdTokens.length ; i++) {
1193 cmdTokens[i] = parameterSubstitutionInGrunt(cmdTokens[i]);
1194 }
1195 if(mExplain == null) { // process only if not in "explain" mode
1196 try {
1197 executeBatch();
1198
1199 // For sh command, create a process with the following syntax
1200 // <shell exe> <invoke arg> <command-as-string>
1201 String shellName = "sh";
1202 String shellInvokeArg = "-c";
1203
1204 // Insert cmd /C in front of the array list to execute to
1205 // support built-in shell commands like mkdir on Windows
1206 if (System.getProperty("os.name").startsWith("Windows")) {
1207 shellName = "cmd";
1208 shellInvokeArg = "/C";
1209 }
1210
1211 List<String> stringList = new ArrayList<String>();
1212 stringList.add(shellName);
1213 stringList.add(shellInvokeArg);
1214
1215 StringBuffer commandString = new StringBuffer();
1216 for (String currToken : cmdTokens) {
1217 commandString.append(" ");
1218 commandString.append(currToken);
1219 }
1220
1221 stringList.add(commandString.toString());
1222
1223 String[] newCmdTokens = stringList.toArray(new String[0]);
1224
1225 Process executor = Runtime.getRuntime().exec(newCmdTokens);
1226
1227 StreamPrinter outPrinter = new StreamPrinter(executor.getInputStream(), null, System.out);
1228 StreamPrinter errPrinter = new StreamPrinter(executor.getErrorStream(), null, System.err);
1229
1230 outPrinter.start();
1231 errPrinter.start();
1232
1233 int ret = executor.waitFor();
1234 outPrinter.join();
1235 errPrinter.join();
1236 if (ret != 0 && !mInteractive) {
1237 String s = LoadFunc.join(
1238 (AbstractList<String>) Arrays.asList(cmdTokens), " ");
1239 throw new IOException("sh command '" + s
1240 + "' failed. Please check output logs for details");
1241 }
1242 } catch (Exception e) {
1243 throw new IOException(e);
1244 }
1245 } else {
1246 log.warn("'sh' statement is ignored while processing 'explain -script' or '-check'");

Callers

nothing calls this directly

Calls 13

executeBatchMethod · 0.95
joinMethod · 0.95
getPropertyMethod · 0.80
toArrayMethod · 0.80
validateMethod · 0.65
addMethod · 0.65
appendMethod · 0.65
warnMethod · 0.65
toStringMethod · 0.45
execMethod · 0.45
startMethod · 0.45

Tested by

no test coverage detected