You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by iv...@apache.org on 2014/04/19 20:55:07 UTC
svn commit: r1588693 -
/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Shell.java
Author: ivanmi
Date: Sat Apr 19 18:55:07 2014
New Revision: 1588693
URL: http://svn.apache.org/r1588693
Log:
YARN-1865. ShellScriptBuilder does not check for some error conditions. Contributed by Remus Rusanu.
Modified:
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Shell.java
Modified: hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Shell.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Shell.java?rev=1588693&r1=1588692&r2=1588693&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Shell.java (original)
+++ hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Shell.java Sat Apr 19 18:55:07 2014
@@ -53,6 +53,34 @@ abstract public class Shell {
return IS_JAVA7_OR_ABOVE;
}
+ /**
+ * Maximum command line length in Windows
+ * KB830473 documents this as 8191
+ */
+ public static final int WINDOWS_MAX_SHELL_LENGHT = 8191;
+
+ /**
+ * Checks if a given command (String[]) fits in the Windows maximum command line length
+ * Note that the input is expected to already include space delimiters, no extra count
+ * will be added for delimiters.
+ *
+ * @param commands command parts, including any space delimiters
+ */
+ public static void checkWindowsCommandLineLength(String...commands)
+ throws IOException {
+ int len = 0;
+ for (String s: commands) {
+ len += s.length();
+ }
+ if (len > WINDOWS_MAX_SHELL_LENGHT) {
+ throw new IOException(String.format(
+ "The command line has a length of %d exceeds maximum allowed length of %d. " +
+ "Command starts with: %s",
+ len, WINDOWS_MAX_SHELL_LENGHT,
+ StringUtils.join("", commands).substring(0, 100)));
+ }
+ }
+
/** a Unix command to get the current user's name */
public final static String USER_NAME_COMMAND = "whoami";