Results 1 to 6 of 6
  1. #1
    NARs is offline Member
    Join Date
    Oct 2009
    Posts
    5
    Rep Power
    0

    Default java.io.IOException: error=2, No such file or directory

    hello :
    I'm trying to execute command (//root//Cexe//test) from java application but get the error msg :
    Java Code:
    java.io.IOException: Cannot run program "//root//Cexe//test": java.io.IOException: error=2, No such file or directory
    but i can execute the command //root//Cexe//test from command line window , it's my part of code :
    Java Code:
    String filename="result";
          BufferedWriter bw = new BufferedWriter(new FileWriter(filename));
          Datum datum = null;
          
          String[] cmd={"sudo //root//Cexe//test ",id1};
          
          Process p =null;
          try{
          ProcessBuilder pb = new ProcessBuilder(cmd);
           p = pb.start();
          }
          catch (Exception e)
          {
          bw.write(e.toString()+'\n');  
          bw.write("startprocess----");
          bw.write(cmd[0]);
          bw.write(cmd[1]);
          bw.flush();
          bw.close();
          }
    Any idea why?

    thanks in advance,
    Last edited by NARs; 11-22-2009 at 11:58 AM.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,523
    Blog Entries
    7
    Rep Power
    20

    Default

    Why are you using double slashes? Only backslashes need to be escaped by another backslash.

    kind regards,

    Jos

  3. #3
    NARs is offline Member
    Join Date
    Oct 2009
    Posts
    5
    Rep Power
    0

    Default

    Quote Originally Posted by JosAH View Post
    Why are you using double slashes? Only backslashes need to be escaped by another backslash.

    kind regards,

    Jos
    hi Jos :
    but when i modify the cmd as follows
    String[] cmd={"sudo /root/Cexe//test ",id1};

    the same error msg again !

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,523
    Blog Entries
    7
    Rep Power
    20

    Default

    I can still see a double slash character there; but what if the sudo command requires a password? I don't see your code supplying one ...

    kind regards,

    Jos

  5. #5
    NARs is offline Member
    Join Date
    Oct 2009
    Posts
    5
    Rep Power
    0

    Default

    hi Jos :
    these if part of my code, i have check the cmd array have save my command (/root/progdir/test arg1)
    Java Code:
    try{
          String filename="result";
          BufferedWriter bw = new BufferedWriter(new FileWriter(filename));
          Datum datum = null;
          String path ="/root/progdir/test  ";
          String[] cmd={path,arg1};
          bw.write(cmd[0]);  //command 
          bw.write(cmd[1]);
          
          try{
            
                 ProcessBuilder pb = new ProcessBuilder(cmd);
                     p = pb.start();
                  
              
              bw.flush();
              bw.close();
     
          }
          catch (Exception e)
          {
          bw.write(e.toString()+'\n');  
          bw.write("startprocess----");
          bw.write(cmd[0]);
          bw.write(cmd[1]);
          bw.flush();
          bw.close();
          }
    but still can't execute the command using ProcessBuilder .
    Any idea will be appreciated!
    cheers ,

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,523
    Blog Entries
    7
    Rep Power
    20

    Default

    Don't use trailing spaces in your path or any of the argument parameters. Read the API documentation for the Process class or any of the Runtime.exec( ... ) methods.

    kind regards,

    Jos

Similar Threads

  1. IOException error
    By eeraj in forum AWT / Swing
    Replies: 3
    Last Post: 08-31-2009, 04:05 AM
  2. IOException error
    By eeraj in forum AWT / Swing
    Replies: 0
    Last Post: 08-29-2009, 09:12 AM
  3. IOException error
    By eeraj in forum AWT / Swing
    Replies: 0
    Last Post: 08-29-2009, 09:02 AM
  4. Error: unreported exception java.io.IOException; ??
    By jonsamwell in forum New To Java
    Replies: 5
    Last Post: 08-24-2008, 04:11 AM
  5. Replies: 3
    Last Post: 04-10-2008, 09:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •