1
votes

I have a method which executes the linux shell commands using the ProcessBuilder API.But, when i am trying to execute the Runnable Jar created from the eclipse it gives me the error as below. I have gone through many blogs and posts but unable to resolve the issue.

I am using java 1.7

XARGS Command gives me the below info

xargs --show-limits
Your environment variables take up 3064 bytes
POSIX upper limit on argument length (this system): 2616328
POSIX smallest allowable upper limit on argument length (all systems): 4096
Maximum length of command we could actually use: 2613264
Size of command buffer we are actually using: 131072



List<String> list = getList();
            for(Iterator<String> itr = list.iterator();itr.hasNext();)
            {

                String command = itr.next();
                System.out.println("Length of String "+command.length());
                LOGGER.info("Executing the command \n"+ command);
                ProcessBuilder processbuilder = new ProcessBuilder(command);
                processbuilder.redirectErrorStream(true);
                Process process = processbuilder.start();
                process.waitFor();
            }

: error=36, File name too long at java.lang.ProcessBuilder.start(ProcessBuilder.java:1047) at com.cisco.parallelexecutor.ParallelExecutor.main(ParallelExecutor.java:35) Caused by: java.io.IOException: error=36, File name too long at java.lang.UNIXProcess.forkAndExec(Native Method) at java.lang.UNIXProcess.(UNIXProcess.java:186) at java.lang.ProcessImpl.start(ProcessImpl.java:130) at java.lang.ProcessBuilder.start(ProcessBuilder.java:1028) ... 1 more

Command which i am trying to run

SQOOP_XXCCS_DS_SAHDR_CORE=ssh hddev-c01-edge-02 "sqoop import -D mapred.child.java.opts='\-Djava.security.egd=file:/dev/../dev/urandom' --connect 'jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=*****.cisco.com)(PORT=&&&&))(CONNECT_DATA=(SERVICE_NAME=*****.COM)(Server=Dedicated)))' --username *** --password **** --query \"select CONTRACT_ID,CONTRACT_NUMBER,CONTRACT_STS_CODE,CONTRACT_STATUS,SERVICE_LINE_ID,SERVICE_LINE_NAME,SERVICE_LINE_STS_CODE,SERVICE_LINE_STATUS,SERVICE_LINE_NUMBER,HDR_CUST_ACCOUNT_ID,HDR_CUST_ACCOUNT_NUMBER,HDR_PARTY_ID,HDR_CUSTOMER_NAME,LINE_CUST_ACCOUNT_ID,LINE_CUST_ACCOUNT_NUMBER,LINE_PARTY_ID,LINE_CUSTOMER_NAME,BILL_TO_SITE_USE_ID,BILL_TO_SITE_USE_NAME,BILL_TO_SITE_USE_STS,BILL_TO_CUST_ACCT_ID,BILL_TO_CUST_ACCT_NUMBER,BILL_TO_CUST_ACCT_STS,BILL_TO_CUST_ACCT_SITE_ID,BILL_TO_CUST_ACCT_SITE_STS,BILL_TO_PARTY_ID,BILL_TO_PARTY_NUMBER,BILL_TO_CUSTOMER_NAME,BILL_TO_PARTY_STS,BILL_TO_PARTY_SITE_ID,BILL_TO_PARTY_SITE_STS,BILL_TO_LOCATION_ID,BILL_TO_COUNTRY,BILL_TO_STATE_PROV,BILL_TO_CITY,BILL_TO_POSTAL_CODE,COVERAGE_TEMPLATE_ID,COVERAGE_TEMPLATE_NAME,COVERAGE_TEMPLATE_DESC,COVERAGE_BEGIN_DATE,COVERAGE_END_DATE,SERVICE_SALES_REP_USR_ID,SERVICE_SALES_REP_USR_NAME,SERVICE_LINE_INVENTORY_ITEM_ID,BILLTO_CSC_ID,BILLTO_CSC_NAME,BILLTO_GU_ID,BILLTO_GU_NAME,BILL_TO_CUSTOMER_SALES_CHANNEL,CURRENCY_CODE,CONTRACT_LIST_AMT,CONTRACT_NET_AMT,USD_CONTRACT_LIST_AMT,USD_CONTRACT_NET_AMT,ACCOUNT_TEAM,RENEWAL_SSR,RENEWAL_TEAM,SALES_REGION,ADVANCE_CONTRACT_FLAG,EARLIEST_END_DATE,SERVICE_LINE_TERMINATED_DATE,SVC_LINE_TERMINATION_REASON,CONTRACT_TERMINATED_DATE,USD_CONV_RATE,PRICE_TYPE,NET_VALUE,COTERM_DATE,MARKETING_PROGRAM,MASTER_AGREEMENT_END_DATE,DISCOUNT_PERCENT,PRORATE_FLAG,RGP_ID,CREATION_DATE,CREATED_BY,LAST_UPDATE_DATE,LAST_UPDATED_BY,LAST_UPDATED_LOGIN,REQUEST_ID,PROGRAM_UPDATE_DATE,PROGRAM_APPLICATION_ID,PROGRAM_ID,ATTRIBUTE_CATEGORY,ATTRIBUTE1,ATTRIBUTE2,ATTRIBUTE3,ATTRIBUTE4,ATTRIBUTE5,ATTRIBUTE6,ATTRIBUTE7,ATTRIBUTE8,ATTRIBUTE9,ATTRIBUTE10,ATTRIBUTE11,ATTRIBUTE12,ATTRIBUTE13,ATTRIBUTE14,ATTRIBUTE15,ATTRIBUTE16,ATTRIBUTE17,ATTRIBUTE18,ATTRIBUTE19,ATTRIBUTE20,ACCOUNT_SSR,SHELL_CONTRACT_FLAG,CONTRACT_START_DATE,CONTRACT_END_DATE from XXCCS_DS_SAHDR_CORE where \\\$CONDITIONS \" --split-by CONTRACT_NUMBER -m 4 --null-string '\\\\N' --null-non-string '\\\\N' --hive-delims-replacement '<EOL>' --boundary-query 'select (select min(CONTRACT_NUMBER) from XXCCS_DS_SAHDR_CORE) as minid ,(select max(CONTRACT_NUMBER) from XXCCS_DS_SAHDR_CORE) as maxid from dual' --target-dir /app/dev/SmartAnalytics/sqoop_temp//XXCCS_DS_SAHDR_CORE --hive-import --hive-overwrite --hive-table installbase.XXCCS_DS_SAHDR_CORE --map-column-hive CONTRACT_ID=BIGINT,SERVICE_LINE_ID=BIGINT,HDR_CUST_ACCOUNT_ID=BIGINT,HDR_PARTY_ID=BIGINT,LINE_CUST_ACCOUNT_ID=BIGINT,LINE_PARTY_ID=BIGINT,BILL_TO_SITE_USE_ID=BIGINT,BILL_TO_CUST_ACCT_ID=BIGINT,BILL_TO_CUST_ACCT_SITE_ID=BIGINT,BILL_TO_PARTY_ID=BIGINT,BILL_TO_PARTY_SITE_ID=BIGINT,BILL_TO_LOCATION_ID=BIGINT,COVERAGE_TEMPLATE_ID=BIGINT,COVERAGE_BEGIN_DATE=TIMESTAMP,COVERAGE_END_DATE=TIMESTAMP,SERVICE_LINE_INVENTORY_ITEM_ID=BIGINT,BILLTO_CSC_ID=BIGINT,BILLTO_GU_ID=BIGINT,CONTRACT_LIST_AMT=BIGINT,CONTRACT_NET_AMT=BIGINT,USD_CONTRACT_LIST_AMT=BIGINT,USD_CONTRACT_NET_AMT=BIGINT,EARLIEST_END_DATE=TIMESTAMP,SERVICE_LINE_TERMINATED_DATE=TIMESTAMP,CONTRACT_TERMINATED_DATE=TIMESTAMP,USD_CONV_RATE=BIGINT,NET_VALUE=BIGINT,MASTER_AGREEMENT_END_DATE=TIMESTAMP,DISCOUNT_PERCENT=BIGINT,PRORATE_FLAG=STRING,RGP_ID=BIGINT,CREATION_DATE=TIMESTAMP,CREATED_BY=BIGINT,LAST_UPDATE_DATE=TIMESTAMP,LAST_UPDATED_BY=BIGINT,LAST_UPDATED_LOGIN=BIGINT,REQUEST_ID=BIGINT,PROGRAM_UPDATE_DATE=TIMESTAMP,PROGRAM_APPLICATION_ID=BIGINT,PROGRAM_ID=BIGINT,ATTRIBUTE_CATEGORY=STRING,ATTRIBUTE1=STRING,ATTRIBUTE2=STRING,ATTRIBUTE3=STRING,ATTRIBUTE4=STRING,ATTRIBUTE5=STRING,ATTRIBUTE6=STRING,ATTRIBUTE7=STRING,ATTRIBUTE8=STRING,ATTRIBUTE9=STRING,ATTRIBUTE10=STRING,ATTRIBUTE11=STRING,ATTRIBUTE12=STRING,ATTRIBUTE13=STRING,ATTRIBUTE14=STRING,ATTRIBUTE15=STRING,ATTRIBUTE16=STRING,ATTRIBUTE17=STRING,ATTRIBUTE18=STRING,ATTRIBUTE19=STRING,ATTRIBUTE20=STRING,ACCOUNT_SSR=STRING,SHELL_CONTRACT_FLAG=STRING,CONTRACT_START_DATE=TIMESTAMP,CONTRACT_END_DATE=TIMESTAMP" >> /apps/pentaho_nfs/installbase/input/poc/logs/IB_logs.log 2>&1

Length of the String is 4260

3
yes it is a meaningless exception.wandermonk
"Length of the String is 4260". That's 4.2 KB file name. Are you sure that this doesn't exceed the limit?Ashwin Gupta

3 Answers

4
votes

ProcessBuilder has two constructors. You're using this one:
ProcessBuilder(String... command)

The first parameter is the command to run, and any subsequent parameters are the arguments to the command.

Since you're passing a single string, the entire string is the command, aka the program. No command-line arguments given. The error message means exactly what it says: File name too long

Split your command into multiple strings, and use the redirectXxx() methods to send output to a file.

1
votes

It depends on the OS and the filesystem, but the maximum length of filename that you can reasonably count on portably is generally 1024 characters and the maximum length of any part (between the slashes) is 255.

You didn't mention your OS, but under Linux and NetBSD both, I get:

# getconf PATH_MAX /
4096

# getconf NAME_MAX /
255

And on OS X I get:

% getconf PATH_MAX /
1024

% getconf NAME_MAX /
255

YMMV

-2
votes

Java is lying you.

I get similar problem with a huge command, more than 3000 characters.

But if i get the command copy/paste directlly in the shell it runs perfectly.

Then the problem is not the length of that command, the problem is how Java works with it.

And Yes, Im working witha list of args, and the problem is still the same.