简体   繁体   English

java.io.IOException:无法运行程序“ sudo sh /etc/rc.d/init.d/jbossas7 restart”:error = 2,没有这样的文件或目录

[英]java.io.IOException: Cannot run program “sudo sh /etc/rc.d/init.d/jbossas7 restart”: error=2, No such file or directory

I want to make my app restart JBoss which is using as a Linux service. 我想让我的应用重新启动用作Linux服务的JBoss。 This is how I do: 这是我的方法:

String array[] = { "sudo sh /etc/rc.d/init.d/jbossas7 restart", "login" };
String pas = "pass";
Process proc = null;
BufferedWriter writer = null;
try {
    proc = Runtime.getRuntime().exec(array);
    writer =
            new BufferedWriter(new OutputStreamWriter(proc.getOutputStream()));
    writer.write(pas);
} catch (IOException e) {
    e.printStackTrace();
}

The jbossas7 contents: jbossas7内容:

#!/bin/bash### BEGIN INIT INFO  
#chkconfig: 345 90 10
#description: JBOSS 7
#processname: jbossas7
#Provides:          jbossas7  
#Required-Start:    $local_fs $remote_fs $network $syslog  
#Required-Stop:     $local_fs $remote_fs $network $syslog  
#Default-Start:     2 3 4 5  
#Default-Stop:      0 1 6  
#Short-Description: Start/Stop JBoss AS 7  
### END INIT INFO      



    ## Include some script files in order to set and export environmental variables  
    ## as well as add the appropriate executables to $PATH.  
    [ -r /etc/profile.d/java.sh ] && . /etc/profile.d/java.sh  
    [ -r /etc/profile.d/jboss.sh ] && . /etc/profile.d/jboss.sh  

    JBOSS_HOME=/usr/local/jboss-eap-6.2  

    AS7_OPTS="$AS7_OPTS -Dorg.apache.tomcat.util.http.ServerCookie.ALLOW_HTTP_SEPARATORS_IN_V0=true"   ## See AS7-1625  
    AS7_OPTS="$AS7_OPTS -Djboss.bind.address.management=0.0.0.0"  
    AS7_OPTS="$AS7_OPTS -Djboss.bind.address=0.0.0.0"  

    case "$1" in  
        start)  
            echo "Starting JBoss AS 7..."  
            #sudo -u jboss sh ${JBOSS_HOME}/bin/standalone.sh $AS7_OPTS           ##  If running as user "jboss"  
            #start-stop-daemon --start --quiet --background --chuid jboss --exec ${JBOSS_HOME}/bin/standalone.sh $AS7_OPTS   ## Ubuntu  
            ${JBOSS_HOME}/bin/standalone.sh $AS7_OPTS &  
        ;;  
        stop)  
            echo "Stopping JBoss AS 7..."  
            #sudo -u jboss sh ${JBOSS_HOME}/bin/jboss-admin.sh --connect command=:shutdown            ##  If running as user "jboss"  
            #start-stop-daemon --start --quiet --background --chuid jboss --exec ${JBOSS_HOME}/bin/jboss-admin.sh -- --connect command=:shutdown     ## Ubuntu  
            ${JBOSS_HOME}/bin/jboss-cli.sh --connect command=:shutdown  
        ;;

    restart)
      echo "Stopping JBoss AS 7..."  
            #sudo -u jboss sh ${JBOSS_HOME}/bin/jboss-admin.sh --connect command=:shutdown            ##  If running as user "jboss"  
            #start-stop-daemon --start --quiet --background --chuid jboss --exec ${JBOSS_HOME}/bin/jboss-admin.sh -- --connect command=:shutdown     ## Ubuntu  
            ${JBOSS_HOME}/bin/jboss-cli.sh --connect command=:shutdown  
    echo "Starting JBoss AS 7..."  
            #sudo -u jboss sh ${JBOSS_HOME}/bin/standalone.sh $AS7_OPTS           ##  If running as user "jboss"  
            #start-stop-daemon --start --quiet --background --chuid jboss --exec ${JBOSS_HOME}/bin/standalone.sh $AS7_OPTS   ## Ubuntu  
            ${JBOSS_HOME}/bin/standalone.sh $AS7_OPTS &  


    ;;  

        *)  
            echo "Usage: /etc/init.d/jbossas7 {start|stop|restart}"; exit 1;  
        ;;  
    esac  

    exit 0  

The command: 命令:

sudo sh /etc/rc.d/init.d/jbossas7 restart

works well currently in terminal mode. 目前在终端模式下运作良好。 But my code says 但是我的代码说

java.io.IOException: Cannot run program "sudo sh /etc/rc.d/init.d/jbossas7 restart": error=2, No such file or directory

What's wrong? 怎么了?

The first element of the input array is being interpreted as the executable. 输入数组的第一个元素被解释为可执行文件。 Try 尝试

String array[] = 
        { "sudo", "sh", "/etc/rc.d/init.d/jbossas7", "restart", "login" };

暂无
暂无

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

相关问题 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 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 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 无法启动测试系统'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: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 线程“main”中的异常java.io.IOException:无法运行程序“”:错误=2,没有这样的文件或目录 - Exception in thread "main" java.io.IOException: Cannot run program "": error=2, No such a 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:无法运行程序“hive”:错误=2,没有那个文件或目录 - Import failed: java.io.IOException: Cannot run program "hive": error=2, No such file or directory spark 2.0-java.io.IOException:无法运行程序“ jupyter”:error = 2,没有这样的文件或目录 - spark 2.0 - java.io.IOException: Cannot run program “jupyter”: error=2, No such file or directory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM