You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pig.apache.org by da...@apache.org on 2012/10/31 23:19:11 UTC
svn commit: r1404386 - in /pig/trunk: CHANGES.txt
src/org/apache/pig/impl/streaming/ExecutableManager.java
src/org/apache/pig/tools/grunt/GruntParser.java
Author: daijy
Date: Wed Oct 31 22:19:11 2012
New Revision: 1404386
URL: http://svn.apache.org/viewvc?rev=1404386&view=rev
Log:
PIG-2801: grunt "sh" command should invoke the shell implicitly instead of calling exec directly with the command tokens
(jgordon via daijy)
Modified:
pig/trunk/CHANGES.txt
pig/trunk/src/org/apache/pig/impl/streaming/ExecutableManager.java
pig/trunk/src/org/apache/pig/tools/grunt/GruntParser.java
Modified: pig/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/pig/trunk/CHANGES.txt?rev=1404386&r1=1404385&r2=1404386&view=diff
==============================================================================
--- pig/trunk/CHANGES.txt (original)
+++ pig/trunk/CHANGES.txt Wed Oct 31 22:19:11 2012
@@ -42,6 +42,9 @@ OPTIMIZATIONS
BUG FIXES
+PIG-2801: grunt "sh" command should invoke the shell implicitly instead of calling exec directly with the command tokens
+(jgordon via daijy)
+
PIG-2885: TestJobSumission and TestHBaseStorage don't work with HBase 0.94 and ZK 3.4.3 (cheolsoo via sms)
PIG-2928: Fix e2e test failures in trunk: FilterBoolean_23/24 (cheolsoo via dvryaboy)
Modified: pig/trunk/src/org/apache/pig/impl/streaming/ExecutableManager.java
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/impl/streaming/ExecutableManager.java?rev=1404386&r1=1404385&r2=1404386&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/impl/streaming/ExecutableManager.java (original)
+++ pig/trunk/src/org/apache/pig/impl/streaming/ExecutableManager.java Wed Oct 31 22:19:11 2012
@@ -220,14 +220,6 @@ public class ExecutableManager {
String cwd = (dir != null) ? dir.getAbsolutePath() : System
.getProperty("user.dir");
- if (System.getProperty("os.name").toUpperCase().startsWith("WINDOWS")) {
- String unixCwd = FileLocalizer.parseCygPath(cwd, FileLocalizer.STYLE_UNIX);
- if (unixCwd == null)
- throw new RuntimeException(
- "Can not convert Windows path to Unix path under cygwin");
- cwd = unixCwd;
- }
-
String envPath = env.get(PATH);
if (envPath == null) {
envPath = cwd;
@@ -274,12 +266,19 @@ public class ExecutableManager {
protected void exec() throws IOException {
// Set the actual command to run with 'bash -c exec ...'
List<String> cmdArgs = new ArrayList<String>();
- cmdArgs.add(BASH);
- cmdArgs.add("-c");
- StringBuffer sb = new StringBuffer();
- sb.append("exec ");
- sb.append(argvAsString);
- cmdArgs.add(sb.toString());
+
+ if (System.getProperty("os.name").toUpperCase().startsWith("WINDOWS")) {
+ cmdArgs.add("cmd");
+ cmdArgs.add("/c");
+ cmdArgs.add(argvAsString);
+ } else {
+ cmdArgs.add(BASH);
+ cmdArgs.add("-c");
+ StringBuffer sb = new StringBuffer();
+ sb.append("exec ");
+ sb.append(argvAsString);
+ cmdArgs.add(sb.toString());
+ }
// Start the external process
ProcessBuilder processBuilder = new ProcessBuilder(cmdArgs
Modified: pig/trunk/src/org/apache/pig/tools/grunt/GruntParser.java
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/tools/grunt/GruntParser.java?rev=1404386&r1=1404385&r2=1404386&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/tools/grunt/GruntParser.java (original)
+++ pig/trunk/src/org/apache/pig/tools/grunt/GruntParser.java Wed Oct 31 22:19:11 2012
@@ -32,6 +32,7 @@ import java.io.Reader;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.AbstractList;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.Enumeration;
@@ -1044,7 +1045,34 @@ public class GruntParser extends PigScri
try {
executeBatch();
- Process executor = Runtime.getRuntime().exec(cmdTokens);
+ // For sh command, create a process with the following syntax
+ // <shell exe> <invoke arg> <command-as-string>
+ String shellName = "sh";
+ String shellInvokeArg = "-c";
+
+ // Insert cmd /C in front of the array list to execute to
+ // support built-in shell commands like mkdir on Windows
+ if (System.getProperty("os.name").startsWith("Windows")) {
+ shellName = "cmd";
+ shellInvokeArg = "/C";
+ }
+
+ List<String> stringList = new ArrayList<String>();
+ stringList.add(shellName);
+ stringList.add(shellInvokeArg);
+
+ StringBuffer commandString = new StringBuffer();
+ for (String currToken : cmdTokens) {
+ commandString.append(" ");
+ commandString.append(currToken);
+ }
+
+ stringList.add(commandString.toString());
+
+ String[] newCmdTokens = stringList.toArray(new String[0]);
+
+ Process executor = Runtime.getRuntime().exec(newCmdTokens);
+
StreamPrinter outPrinter = new StreamPrinter(executor.getInputStream(), null, System.out);
StreamPrinter errPrinter = new StreamPrinter(executor.getErrorStream(), null, System.err);