简体   繁体   English

java.io.IOException:无法运行程序“/usr/bin/sh”:java.io.IOException:error=2,没有那个文件或目录

[英]java.io.IOException: Cannot run program “/usr/bin/sh”: java.io.IOException: error=2, No such file or directory

i wanted to perform rename and delete function and the environment is LINUX.我想执行重命名和删除功能,环境是LINUX。 This is the code which I'm using,这是我正在使用的代码,

String[] command_ary = { "/usr/bin/sh", "-c", command };
Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec( command_ary );

But Im getting the following error message,但我收到以下错误消息,

java.io.IOException: Cannot run program "/usr/bin/sh": java.io.IOException: error=2, No such file or directory

Can anybody help me.有谁能够帮我。 Thank-You谢谢

As the exception says, there's no file /usr/bin/sh on your system.正如例外所说,您的系统上没有文件/usr/bin/sh If you're looking for the Bourne shell, that's /bin/sh .如果您正在寻找 Bourne shell,那就是/bin/sh

public void run() { //log.info("taskDao:{},concurrentHashSet:{},id:{},shellName:{},shellDate:{}", taskDao, concurrentHashSet, id, shellName, shellDate); log.info("concurrentHashSet:{},param:{}", concurrentHashSet, param); int exeState = 99999; // ssh跳转到其他机器去执行脚本,you can add "ssh rd@g1-jg-hadoop-01 \"source ~/.bash_profile ; bash -x %s %s\"" instead of command String command = "source ~/.bash_profile ; bash -x %s %s"; String commandF = String.format(command, param.getShellName(), param.getRecallDate()); String[] cmdArr = {"/bin/sh", "-c", commandF}; long taskId = param.getTaskId(); Runtime runtime = Runtime.getRuntime(); Process process = null; try { process = runtime.exec(cmdArr); InputStream stderr = process.getErrorStream(); InputStreamReader isr = new InputStreamReader(stderr); BufferedReader br = new BufferedReader(isr); String line = null; StringBuilder sb = new StringBuilder(); while ((line = br.readLine()) != null) { sb.append(line).append(System.lineSeparator()); } log.info("exe task thread param:{},commandF:{},execute shell info:{}", param, commandF, sb.toString()); exeState = process.waitFor(); } catch (InterruptedException | IOException e) { log.error("execute shell error,exeState:{},command:{}", exeState, commandF,e); } finally { log.info("execute shell state:{}", exeState); // 从set中删除 更新表状态 多张表一个脚本,会有问题,其中状态覆盖 if (exeState == 0) { // 执行成功 taskDao.updateStateByPrimaryKey(taskId, (short) 30, new Date()); // 邮件参数 param.setState(30); String mailBody = SendMailUtil.beautyMailHtmlLayout(param); String mailToAddress = param.getMailToUser(); String mailTitle = param.getMailContentTitle(); try { SendMailUtil.sendMail(mailToAddress, mailTitle, mailBody); } catch (Exception e) { e.printStackTrace(); } } if (exeState != 0) { // 执行失败 taskDao.updateStateByPrimaryKey(taskId, (short) 40, new Date()); // 邮件参数 param.setState(40); String mailBody = SendMailUtil.beautyMailHtmlLayout(param); String mailToAddress = param.getMailToUser(); try { SendMailUtil.sendMail(mailToAddress, "回溯任务", mailBody); } catch (Exception e) { e.printStackTrace(); } } ExecuteTaskModel taskModel = new ExecuteTaskModel(); taskModel.setId(taskId); log.info("remove task in thread,id:{}", taskId); boolean remove; if (concurrentHashSet.contains(taskModel)) { remove = concurrentHashSet.remove(taskModel); } log.info("remove from set success set:{}", concurrentHashSet); log.info("execute task thread exit!"); System.out.println("Process exitValue: " + exeState); assert process != null; process.destroy(); } }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.io.IOException:无法运行程序“usr/bin/ffmpeg”:错误=2,没有那个文件或目录 - java.io.IOException: Cannot run program “usr/bin/ffmpeg ”: error=2, No such file or directory java.io.IOException: 无法运行程序“...”: java.io.IOException: error=2, No such file or directory - java.io.IOException: Cannot run program “…”: java.io.IOException: error=2, No such file or directory JVM无法启动:java.io.IOException:无法运行程序“/ usr / libexec / StartupItemContext; error = 2,没有这样的文件或目录 - JVM failed to start: java.io.IOException: Cannot run program "/usr/libexec/StartupItemContext; error=2, No such file or directory java.io.IOException:无法运行程序“ C:\\ AutoIt \\ ModenaAutoIt.exe”:java.io.IOException:error = 2,没有此类文件或目录 - java.io.IOException: Cannot run program “C:\AutoIt\ModenaAutoIt.exe”: java.io.IOException: error=2, No such file or directory 无法运行程序java.io.IOException - Cannot run program java.io.IOException java.io.IOException:Cannot run program "sh" (in directory "c:\\cygwin\\bin\\test"):CreateProcess error=2.The system cannot find file specified - java.io.IOException:Cannot run program “sh” (in directory“c:\cygwin\bin\test”):CreateProcess error=2.The system cannot find file specified 在 java 中,出现错误“无法运行程序”/bin/sh“:java.io.IOException: error=24, Too many open files” - in java,getting error “Cannot run program ”/bin/sh“: java.io.IOException: error=24, Too many open files” 无法启动测试系统'slim':java.io.IOException:无法运行程序“ java”:error = 2,没有这样的文件或目录 - Unable to start test system 'slim': java.io.IOException: Cannot run program “java”: error=2, No such file or directory ant jar错误:执行失败:java.io.IOException:无法运行程序... $ {aapt}“:error = 2,没有这样的文件或目录 - ant jar error: Execute failed: java.io.IOException: Cannot run program…${aapt}": error=2, No such file or directory java.io.IOException: error=2, 没有那个文件或目录 - java.io.IOException: error=2, No such file or directory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM