java.io.IOException:error = 36,java中的文件名太长了

时间:2016-02-24 05:30:32

标签: java eclipse processbuilder

我有一个使用ProcessBuilder API执行linux shell命令的方法。但是,当我尝试执行从eclipse创建的Runnable Jar时,它给出了如下错误。我浏览了很多博客和帖子,但无法解决问题。

我正在使用java 1.7

XARGS Command给我以下信息

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();
            }
  

:错误= 36,文件名太长           在java.lang.ProcessBuilder.start(ProcessBuilder.java:1047)           在com.cisco.parallelexecutor.ParallelExecutor.main(ParallelExecutor.java:35)   引起:java.io.IOException:error = 36,文件名太长           at java.lang.UNIXProcess.forkAndExec(Native Method)           在java.lang.UNIXProcess。(UNIXProcess.java:186)           在java.lang.ProcessImpl.start(ProcessImpl.java:130)           在java.lang.ProcessBuilder.start(ProcessBuilder.java:1028)           ......还有1个

我正在尝试运行的命令

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

字符串的长度为4260

3 个答案:

答案 0 :(得分:3)

ProcessBuilder有两个构造函数。你正在使用这个:
ProcessBuilder(String... command)

first 参数是要运行的命令,任何后续参数都是命令的参数。

由于您传递了一个字符串,整个字符串是命令,即程序。没有给出命令行参数。错误消息的确切含义如下:File name too long

将命令拆分为多个字符串,并使用redirectXxx()方法将输出发送到文件。

答案 1 :(得分:1)

这取决于操作系统和文件系统,但是可以合理依赖的文件名的最大长度通常为1024个字符,任何部分(斜杠之间)的最大长度为255.

你没有提到你的操作系统,但是在Linux和NetBSD下,我得到了:

# getconf PATH_MAX /
4096

# getconf NAME_MAX /
255

在OS X上我得到:

% getconf PATH_MAX /
1024

% getconf NAME_MAX /
255

YMMV

答案 2 :(得分:-1)

Java在骗你。

我遇到类似的问题,一个巨大的命令,超过3000个字符。

但是,如果我在shell中直接获得命令copy / paste,它就能完美运行。

然后问题不在于该命令的长度,问题在于Java如何使用它。

是的,我正在使用args列表,问题仍然是一样的。