Return-Path: X-Original-To: apmail-hadoop-common-commits-archive@www.apache.org Delivered-To: apmail-hadoop-common-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id F31871061A for ; Sat, 19 Apr 2014 19:01:05 +0000 (UTC) Received: (qmail 93921 invoked by uid 500); 19 Apr 2014 19:01:04 -0000 Delivered-To: apmail-hadoop-common-commits-archive@hadoop.apache.org Received: (qmail 93792 invoked by uid 500); 19 Apr 2014 19:01:04 -0000 Mailing-List: contact common-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: common-dev@hadoop.apache.org Delivered-To: mailing list common-commits@hadoop.apache.org Received: (qmail 93785 invoked by uid 99); 19 Apr 2014 19:01:04 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 19 Apr 2014 19:01:04 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 19 Apr 2014 19:01:02 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id E09502388B43; Sat, 19 Apr 2014 19:00:42 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1588696 - /hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Shell.java Date: Sat, 19 Apr 2014 19:00:42 -0000 To: common-commits@hadoop.apache.org From: ivanmi@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140419190042.E09502388B43@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: ivanmi Date: Sat Apr 19 19:00:42 2014 New Revision: 1588696 URL: http://svn.apache.org/r1588696 Log: YARN-1865 Merging change r1588693 from trunk. Modified: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Shell.java Modified: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Shell.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Shell.java?rev=1588696&r1=1588695&r2=1588696&view=diff ============================================================================== --- hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Shell.java (original) +++ hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Shell.java Sat Apr 19 19:00:42 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";