Java Runtime.getRuntime()非法参数异常

技术标签: java.  运行时 - 错误

我有一些问题让.getRuntime.exec()正常工作。以下是处理该部分的代码:

while (line != null)
{
  String name = line;
  String commandFull = commandFirst + name + commandLast;

  String[] fullCommand = new String[] {commandFirst, name, commandLast};
  for(int i=0;i<3;i++)
  {
    System.out.print(fullCommand[i]);
  }
  Runtime runner = Runtime.getRuntime();
  Process p = runner.exec(fullCommand);

  outFile.println(fullCommand);

  line = inFile.readLine();
}

它会根据应该看的命令打印出来。当我在这里运行该程序时,输出:

adfind -b dc=stuff,dc=com -f "cn=user" |find "displayName" >> fullList.txt
Exception in thread "main" java.lang.IllegalArgumentException
        at java.lang.ProcessImpl.<init>(Unknown Source)
        at java.lang.ProcessImpl.start(Unknown Source)
        at java.lang.ProcessBuilder.start(Unknown Source)
        at java.lang.Runtime.exec(Unknown Source)
        at java.lang.Runtime.exec(Unknown Source)
        at lookup.main(lookup.java:41)

看答案

您正在尝试在没有shell的情况下执行shell命令。

也就是说,你正试图执行shell将解释的东西(特别是管道 '|' 并附加 '>>')。要解决此问题,请执行Java执行shell实例并将整个命令传递给shell。这将如何工作是平台依赖。

例如在Linux中:

String fullCommand = {"/bin/sh", "-c", "find -b dc=stuff,dc=com -f \"cn=user\" |find \"displayName\" >> fullList.txt"};

或在Windows中:

String fullCommand = {"cmd.exe", "/c", "find -b dc=stuff,dc=com -f \"cn=user\" |find \"displayName\" >> fullList.txt"};

智能推荐

Runtime.getRuntime().exec()执行错误返回为1的原因

一些代码问题我就不说了。 我本地执行的是:cmd /c mvn -T 4 package -Dmaven.test.skip -Dmaven.javadoc.skip=true 排查点有3个,正好我碰到了这些点,记录一下,困扰了我许久 1.环境变量的配置,mvn,java 2.这个命令自己先去cmd窗口执行一下,看能否执行成功 3.我本地是win10系统的,关闭powershell这个功能,然后重...

Java Runtime与异常、事务

Runtime 表示的是运行时的状态对象。是一个封装的JVM类,就像单例一样! Runtime定义了三个方法:totalMemory()可以使用的内存、 maxMemory()最大 可用的内存、 freeMemory()当前空余的内存 Throwable:代表是可抛出的异常。 Error:代表的是严重的错误, Exception:代表的就是异常,分为两种派生类:一种是运行时异常(RuntimeEx...

Java Checked 异常和 Runtime异常体系

Java 异常分为两大类:Checked 异常和 Runtime 异常(运行时异常)。 使用 throws 声明抛出异常 上面程序声明不处理 IOException 异常,将该异常交给 JVM 处理,所以程序一旦遇到该异常,JVM 就会打印该异常的跟踪栈信息,并结束程序,运行上面程序,得到如下结果: 使用 throws 声明抛出异常时有一个限制:子类方法声明抛出的异常类型应该是父类方法声明抛出的异...

记一次Runtime.getRuntime().exec(cmdarrayFinal)多线程使用synchronize连接mysql数据库,线程hung住的问题

  记一次Runtime.getRuntime().exec(cmdarrayFinal)多线程使用synchronize连接mysql数据库,线程hung住的问题   先上截图:datax同步数据,自己改写了master分支加了数据同步加密,然后channel设置多线程有点多时,同步就hung住了   根据日志判断方法hung在哪个方法的调用以及本地debug,主要...

java 非法字符 \ufeff

向数据库中写入数据时出现编码错误 Error:(1, 1) java: 非法字符: ‘\ufeff’ Error:(1, 10) java: 需要class, interface或enum 总结:先选择gbk、然后convert、然后在选择一下utf-8在convert确认下就行了。 其实就是刷新一下utf-8编码...

猜你喜欢

redis中的hash扩容渐进式rehash过程

背景: redis字典(hash表)当数据越来越多的时候,就会发生扩容,也就是rehash 对比:java中的hashmap,当数据数量达到阈值的时候(0.75),就会发生rehash,hash表长度变为原来的二倍,将原hash表数据全部重新计算hash地址,重新分配位置,达到rehash目的 redis中的hash表采用的是渐进式hash的方式: 1、redis字典(hash表)底层有...

不同系统下的回车\r和换行\n,及其历史

2019独角兽企业重金招聘Python工程师标准>>>      我们平时按下键盘上的‘回车键’,就能实现回车换行【我们在屏幕上所看到的就是光标移到了下一行的开头位置!!ps:不讨论软件实现的特殊功能,如word里的回车智能缩进】。因此对这个按键更准确说应该叫做‘回车换行键’ 就且将这种将光标移到下行开...

windows操作系统,python环境下django的自动安装

首先,在Windows操作系统下安装python,完成python环境的搭建。(我看有的博客需要配置环境变量,其实不必要,因为我们在安装的时候只要勾选如下图所示即可避免不必要的麻烦) 第二步,使用快捷键windows+R或者点击如下图所示,之后点击运行 在其中输入cmd即可进入dos命令。 第三步,输入以下命令 就会自动安装,等待安装完成即可。 第四步,检测django是否安装成功,如果出现如下图...

Qt之日志输出文件

    做过项目的童鞋可能都使用过日志功能,以便有异常错误能够快速跟踪、定位,Qt也提供的类似的机制。之前用Qt4做项目时使用的是Qt::qInstallMsgHandler(),到了Qt5,使用了新的Qt::qInstallMessageHandler()来替代,详情请查看Qt助手(C++ API changes)。 描述     助手中在C++ API ...

基于雇员流失率数据进行多分类模型训练及阈值调整实践-大数据ML样本集案例实战

版权声明:本套技术专栏是作者(秦凯新)平时工作的总结和升华,通过从真实商业环境抽取案例进行总结和分享,并给出商业应用的调优建议和集群环境容量规划等内容,请持续关注本套博客。QQ邮箱地址:[email protected],如有任何学术交流,可随时联系。 1 数据的预处理分析 2 数据标准化处理 3 sklearn多模型封装(已废弃,学思想) 4 阈值概率调整 5 总结 方便复习,整成笔记,内容粗略...

问答精选

How to get the sum of rows using a vector and the make the result in a column

I have a dataframe and i want to calculate the sum of variables present in a vector in every row and make the sum in other variable after i want the name of new variable created to be from the name of...

Call a custom class in zend framework

I have a very rough project that done partially in zend framework (not ZF2). The 'application', 'library' and 'public' folders are on the same root. Now i need to create a library 'Anil' in the 'libra...

Hide Some Of The Categories In Magento?

I want to hide some of the categories from magento home page. I have created some categories like New Arrivals, Special Offer Which I would like to show in some different way may be in left panel or r...

Reading an internal file in Android Studio

I am writing to an internal file in Android Studio The code lets me write lines of data split with commas. I am able to then go to another activity and read it all out at once. However I want to be ab...

Rails Acts_as_votable Gem Like/Unlike Buttons with Ajax

I'm new to Ruby On Rails, I used the acts_as_votable gem to create Like and Unlike Buttons to make Users like and unlike Posts but I can't make them change from Like to Unlike (and viceversa) and upda...

相关问题

相关文章

热门文章

推荐文章

相关标签

推荐问答