开发者

Java IOException

开发者 https://www.devze.com 2023-03-02 01:14 出处:网络
I am executing a below program which call the shell through java and I am getting the excepton please help me.

I am executing a below program which call the shell through java and I am getting the excepton please help me.

program:

import java.io.*;
import java.util.*;


public class ProcessExample {

/**
 * @param args
 */
 public static void main(String args[]) throws IOException {

       File file=new File("/opt/nilesh/fazal");


       ProcessBuilder processBuilder = new ProcessBuilder("./LicenseGen.sh --batchfile commands.txt");
       processBuilder.directory(file);
       processBuilder.redirectErrorStream(true);
       System.out.println("nilesh");
        Process 开发者_StackOverflow社区process=processBuilder.start();      

       InputStream is = process.getInputStream();
       InputStreamReader isr = new InputStreamReader(is);
       BufferedReader br = new BufferedReader(isr);

       String line;

       System.out.printf("Output of running %s is:", 
          Arrays.toString(args));

       while ((line = br.readLine()) != null) {
         System.out.println(line);
       }

       OutputStream os=process.getOutputStream();
       OutputStreamWriter osw=new OutputStreamWriter(os);
       BufferedWriter bw=new BufferedWriter(osw);
       bw.write("create licensekey -x license-input.xml");

       while ((line = br.readLine()) != null) {
         System.out.println(line);
       }

     }

}

and the exception

Excepton:Exception in thread "main" java.io.IOException: Cannot run program "./LicenseGen.sh --batchfile commands.tx": java.io.IOException: error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:459)
at ProcessExample.main(ProcessExample.java:23)
Caused by: java.io.IOException: java.io.IOException: error=2, No such file or directory
at java.lang.UNIXProcess.<init>(UNIXProcess.java:148)
at java.lang.ProcessImpl.start(ProcessImpl.java:65)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:452)
... 1 more


ProcessBuilder processBuilder = 
    new ProcessBuilder("./LicenseGen.sh","--batchfile","commands.txt");

You need to pass in the command and args as separate strings or a list.

http://download.oracle.com/javase/6/docs/api/java/lang/ProcessBuilder.html

0

精彩评论

暂无评论...
验证码 换一张
取 消