java process.waitfor返回1的原因及解决

目录
  • java process.waitfor返回1
    • 大致的原因如下
  • process.waitFor()的返回值含义
    • 以下是Linux中返回值对照表

java process.waitfor返回1

java的process,在执行命令时,出现waitfor返回1错误。根据java文档,是operation not permited。但绝大多数情况下,这是瞎扯。

真正原因是,你执行的命令(dos或linux下的命令),java的process执行时候,出错了。而错误本身是在这个命令的字符串上。

大致的原因如下

1. 字符串中包含额外的空格,导致命令不对。比如文件名之类的。解决方案,无非用引号把文件名之类的参数引起来

2. 还一个比较恶心的是,执行的命令,你最好用绝对路径。很多情况下,你要执行的工具可能放在系统默认的路径下,这种情况下,你直接在dos窗口或linux命令行下,执行都是正常的,但是一到程序中,就死活返回1的错误。

3. 另一个process执行返回1的原因可能是:进程执行所需的环境不正确。

当然,我碰到的问题不属于上面情况。Process里执行的shell脚本要操作文件,结果这个文件在其它地方被占用了,导致process执行失败

process.waitFor()的返回值含义

以下是Linux中返回值对照表

"OS error code   1:  Operation not permitted"
"OS error code   2:  No such file or directory"
"OS error code   3:  No such process"
"OS error code   4:  Interrupted system call"
"OS error code   5:  Input/output error"
"OS error code   6:  No such device or address"
"OS error code   7:  Argument list too long"
"OS error code   8:  Exec format error"
"OS error code   9:  Bad file descriptor"
"OS error code  10:  No child processes"
"OS error code  11:  Resource temporarily unavailable"
"OS error code  12:  Cannot allocate memory"
"OS error code  13:  Permission denied"
"OS error code  14:  Bad address"
"OS error code  15:  Block device required"
"OS error code  16:  Device or resource busy"
"OS error code  17:  File exists"
"OS error code  18:  Invalid cross-device link"
"OS error code  19:  No such device"
"OS error code  20:  Not a directory"
"OS error code  21:  Is a directory"
"OS error code  22:  Invalid argument"
"OS error code  23:  Too many open files in system"
"OS error code  24:  Too many open files"
"OS error code  25:  Inappropriate ioctl for device"
"OS error code  26:  Text file busy"
"OS error code  27:  File too large"
"OS error code  28:  No space left on device"
"OS error code  29:  Illegal seek"
"OS error code  30:  Read-only file system"
"OS error code  31:  Too many links"
"OS error code  32:  Broken pipe"
"OS error code  33:  Numerical argument out of domain"
"OS error code  34:  Numerical result out of range"
"OS error code  35:  Resource deadlock avoided"
"OS error code  36:  File name too long"
"OS error code  37:  No locks available"
"OS error code  38:  Function not implemented"
"OS error code  39:  Directory not empty"
"OS error code  40:  Too many levels of symbolic links"
"OS error code  42:  No message of desired type"
"OS error code  43:  Identifier removed"
"OS error code  44:  Channel number out of range"
"OS error code  45:  Level 2 not synchronized"
"OS error code  46:  Level 3 halted"
"OS error code  47:  Level 3 reset"
"OS error code  48:  Link number out of range"
"OS error code  49:  Protocol driver not attached"
"OS error code  50:  No CSI structure available"
"OS error code  51:  Level 2 halted"
"OS error code  52:  Invalid exchange"
"OS error code  53:  Invalid request descriptor"
"OS error code  54:  Exchange full"
"OS error code  55:  No anode"
"OS error code  56:  Invalid request code"
"OS error code  57:  Invalid slot"
"OS error code  59:  Bad font file format"
"OS error code  60:  Device not a stream"
"OS error code  61:  No data available"
"OS error code  62:  Timer expired"
"OS error code  63:  Out of streams resources"
"OS error code  64:  Machine is not on the network"
"OS error code  65:  Package not installed"
"OS error code  66:  Object is remote"
"OS error code  67:  Link has been severed"
"OS error code  68:  Advertise error"
"OS error code  69:  Srmount error"
"OS error code  70:  Communication error on send"
"OS error code  71:  Protocol error"
"OS error code  72:  Multihop attempted"
"OS error code  73:  RFS specific error"
"OS error code  74:  Bad message"
"OS error code  75:  Value too large for defined data type"
"OS error code  76:  Name not unique on network"
"OS error code  77:  File descriptor in bad state"
"OS error code  78:  Remote address changed"
"OS error code  79:  Can not access a needed shared library"
"OS error code  80:  Accessing a corrupted shared library"
"OS error code  81:  .lib section in a.out corrupted"
"OS error code  82:  Attempting to link in too many shared libraries"
"OS error code  83:  Cannot exec a shared library directly"
"OS error code  84:  Invalid or incomplete multibyte or wide character"
"OS error code  85:  Interrupted system call should be restarted"
"OS error code  86:  Streams pipe error"
"OS error code  87:  Too many users"
"OS error code  88:  Socket operation on non-socket"
"OS error code  89:  Destination address required"
"OS error code  90:  Message too long"
"OS error code  91:  Protocol wrong type for socket"
"OS error code  92:  Protocol not available"
"OS error code  93:  Protocol not supported"
"OS error code  94:  Socket type not supported"
"OS error code  95:  Operation not supported"
"OS error code  96:  Protocol family not supported"
"OS error code  97:  Address family not supported by protocol"
"OS error code  98:  Address already in use"
"OS error code  99:  Cannot assign requested address"
"OS error code 100:  Network is down"
"OS error code 101:  Network is unreachable"
"OS error code 102:  Network dropped connection on reset"
"OS error code 103:  Software caused connection abort"
"OS error code 104:  Connection reset by peer"
"OS error code 105:  No buffer space available"
"OS error code 106:  Transport endpoint is already connected"
"OS error code 107:  Transport endpoint is not connected"
"OS error code 108:  Cannot send after transport endpoint shutdown"
"OS error code 109:  Too many references: cannot splice"
"OS error code 110:  Connection timed out"
"OS error code 111:  Connection refused"
"OS error code 112:  Host is down"
"OS error code 113:  No route to host"
"OS error code 114:  Operation already in progress"
"OS error code 115:  Operation now in progress"
"OS error code 116:  Stale NFS file handle"
"OS error code 117:  Structure needs cleaning"
"OS error code 118:  Not a XENIX named type file"
"OS error code 119:  No XENIX semaphores available"
"OS error code 120:  Is a named type file"
"OS error code 121:  Remote I/O error"
"OS error code 122:  Disk quota exceeded"
"OS error code 123:  No medium found"
"OS error code 124:  Wrong medium type"
"OS error code 125:  Operation canceled"
"OS error code 126:  Required key not available"
"OS error code 127:  Key has expired"
"OS error code 128:  Key has been revoked"
"OS error code 129:  Key was rejected by service"
"OS error code 130:  Owner died"
"OS error code 131:  State not recoverable"
"MySQL error code 132: Old database file"
"MySQL error code 133: No record read before update"
"MySQL error code 134: Record was already deleted (or record file crashed)"
"MySQL error code 135: No more room in record file"
"MySQL error code 136: No more room in index file"
"MySQL error code 137: No more records (read after end of file)"
"MySQL error code 138: Unsupported extension used for table"
"MySQL error code 139: Too big row"
"MySQL error code 140: Wrong create options"
"MySQL error code 141: Duplicate unique key or constraint on write or update"
"MySQL error code 142: Unknown character set used"
"MySQL error code 143: Conflicting table definitions in sub-tables of MERGE table"
"MySQL error code 144: Table is crashed and last repair failed"
"MySQL error code 145: Table was marked as crashed and should be repaired"
"MySQL error code 146: Lock timed out; Retry transaction"
"MySQL error code 147: Lock table is full;  Restart program with a larger locktable"
"MySQL error code 148: Updates are not allowed under a read only transactions"
"MySQL error code 149: Lock deadlock; Retry transaction"
"MySQL error code 150: Foreign key constraint is incorrectly formed"
"MySQL error code 151: Cannot add a child row"
"MySQL error code 152: Cannot delete a parent row"

以上为个人经验,希望能给大家一个参考,也希望大家多多支持我们。

(0)

相关推荐

  • java调用process线程阻塞问题的解决

    java调用process线程阻塞问题 项目需求中涉及java调用.bat文件进行图像处理,先直接上简略版程序 public void draw(){ //调用bat脚本进行图像处理 Process process = null; InputStream in = null; try { process = Runtime.getRuntime().exec("startup.bat"); //输出测试 // in = process.getInputStream(); // Stri

  • Java编程使用Runtime和Process类运行外部程序的方法

    本文实例讲述了Java编程使用Runtime和Process类运行外部程序的方法.分享给大家供大家参考,具体如下: 使用Runtime.getRuntime().exec()方法可以在java程序里运行外部程序. 1. exec(String command) 2. exec(String command, String envp[], File dir) 3. exec(String cmd, String envp[]) 4. exec(String cmdarray[]) 5. exec(

  • Java Process.waitFor()方法详解

    目录 Java Process.waitFor()方法 描述 声明 参数 返回值 异常 实例 process.waitFor()没有作用 Java Process.waitFor()方法 Process.waitFor()方法 将导致当前线程等待,直到该对象的进程结束,才返回调用. 描述 java.lang.Process.waitFor()方法将导致当前的线程等待,如果必要的话,直到由该Process对象表示的进程已经终止.此方法将立即返回,如果子进程已经终止.如果子进程尚未终止,则调用线程将

  • 调用Process.waitfor导致的进程挂起问题及解决

    目录 问题背景 问题描述 挂起原因 解决方法 JDK上的说明 背后的故事 测试pipe的大小 Linux上pipe分析 问题背景 如果要在Java中调用shell脚本时,可以使用Runtime.exec或ProcessBuilder.start.它们都会返回一个Process对象,通过这个Process可以对获取脚本执行的输出,然后在Java中进行相应处理. 例如,下面的代码: try { Process process = Runtime.getRuntime().exec(cmd); pro

  • 关于Process的waitFor死锁问题及解决方案

    目录 Process的waitFor死锁问题 1.发现问题 2.原因查找 3.造成死锁原理图 问题代码 解决方案 Java中死锁的简单例子及其避免 我们来看一个死锁的简单例子 那么要怎么预防死锁呢? 下面介绍几个常见方法: Process的waitFor死锁问题 1.发现问题 在实际开发中,进行文件操作时,使用Process对文件进行解压操作,程序执行过程中会出现一直卡在那的问题. 2.原因查找 问题在缓冲区这个地方:可执行程序的标准输出比较多,而运行窗口的标准缓冲区不够大,所以发生阻塞.接着来

  • java process.waitfor返回1的原因及解决

    目录 java process.waitfor返回1 大致的原因如下 process.waitFor()的返回值含义 以下是Linux中返回值对照表 java process.waitfor返回1 java的process,在执行命令时,出现waitfor返回1错误.根据java文档,是operation not permited.但绝大多数情况下,这是瞎扯. 真正原因是,你执行的命令(dos或linux下的命令),java的process执行时候,出错了.而错误本身是在这个命令的字符串上. 大

  • Java内存各部分OOM出现原因及解决方法(必看)

    一,jvm内存区域 1,程序计数器 一块很小的内存空间,作用是当前线程所执行的字节码的行号指示器. 2,java栈 与程序计数器一样,java栈(虚拟机栈)也是线程私有的,其生命周期与线程相同.通常存放基本数据类型,对象引用(一个指向对象起始地址的引用指针或一个代表对象的句柄),reeturnAddress类型(指向一条字节码指令的地址) 栈区域有两种异常类型:如果线程请求的栈深度大于虚拟机所允许的深度,将抛StrackOverflowError异常:如果虚拟机栈可以动态扩展(大部分虚拟机都可动

  • Java String.replace()方法"无效"的原因及解决方式

    首先我们来看个例子 public class Demo1 { public static void main(String[] args) { String aa="abcd"; aa.replace("a","f"); System.out.println("输出结果是"+aa); } } 运行结果是什么呢?我们先看看这个方法的api 返回一个新的字符串,用newChar替换此字符串中出现的所有oldChar 所以这里的结果

  • easyui form validate总是返回false的原因及解决方法

    最近做表单验证用了easyui form组件.又一次发现在测试表单都填写正确了但是调试表单的代码监测到调用form的"validate"方法总是返回false 最后查了一下原因在html中写的是easyui-validatebox但是在script中却又声明了$('#field1').combobox(); <form id="form1"> <input type="text" id="field1" cl

  • java file.renameTo返回false的原因及解决方案

    java file.renameTo返回false原因 需要对文件夹下的文件重命名,发现返回false了,先用main方法测试,发现没问题,如下 public static void main(String[] args) throws IOException { File file1 = new File("D:\\aabb.xml"); File file2 = new File("D:\\ccdd.xml"); boolean b = file1.rename

  • Java Process中waitFor()的问题详解

    目录 总结 在编写Java程序时,有时候我们需要调用其他的诸如exe,shell这样的程序或脚本.在Java中提供了两种方法来启动其他程序: (1) 使用Runtime的exec()方法 (2) 使用ProcessBuilder的start()方法 .Runtime和ProcessBulider提供了不同的方式来启动程序,设置启动参数.环境变量和工作目录.但是这两种方法都会返回一个用于管理操作系统进程的Process对象.这个对象中的waitFor()是我们今天要讨论的重点. 来说说我遇到的实际

  • java使用Process调用exe程序及Process.waitFor()死锁问题解决

    目录 前言 文章参考 1. 使用process调用exe程序 2. waitfor 问题描述分析 3. 死锁问题解决 总结 前言 最近在开发android的同时也在开发java ,碰到了需要使用java 程序调用exe的需求,这里我使用的 process 来调用的.该篇文章 读完需要8+分钟,文章类型为 小白入门类型,此处主要记录,方便以后学习补充… 如有不正确的地方还望海涵 及 指出…. 文章参考 process参考 waitfor挂起解析 1. 使用process调用exe程序 Proces

  • 使用Runtime 调用Process.waitfor导致的阻塞问题

    目录 1. 关于Runtime类的小知识 2. Runtime的几个重要的重载方法 3. Runtime的使用方式 4. 卡死原因 5. 解决方案 6. Runtime最优雅的调用方式 1. 关于Runtime类的小知识 Runtime.getRuntime()可以取得当前JVM的运行时环境,这也是在Java中唯一一个得到运行时环境的方法 Runtime中的exit方法是退出JVM 2. Runtime的几个重要的重载方法 方法名 作用 exec(String command); 在单独的进程中

随机推荐