Results 1 to 4 of 4
  1. #1
    nath02 is offline Member
    Join Date
    Sep 2014
    Posts
    2
    Rep Power
    0

    Unhappy Problems with Process.exec (long arguments, complex command line)

    Hello everybody

    I have to call, from my java application (developped on Netbeans 8.0, Ubuntu) another java program. When I just want to call it in the Shell terminal, I use this +/- complex command lign :

    java -Xmx1G -classpath /home/user/software/a.jar:/home/user/software/b.jar:/home/user/software/c.jar:/home/user/software/d.jar:. /home/user/software/Script 0 1 0 1 /home/user/LSEQU/ 1000 32 1000 32 10 28 1000 1191 1 1 0 0 0 0 S 25 90 0 0 0 0 T 0 100 1 0.0 1000 /home/user/tmp/ Model 0 B 0 0 CLASSIC 0 1 LIBSVM /home/user/software/libsvm/ 0 L 1 1 S 0

    Actually, /home/user/software/Script is the Script.java to run, to launch the "software" application. "0 1 0 1 /home/user/LSEQU/ 1000 32 1000 32 10 28 1000 1191 1 1 0 0 0 0 S 25 90 0 0 0 0 y wellT 0 100 1 0.0 1000 /home/user/tmp/ Model 0 B 0 0 CLASSIC 0 1 LIBSVM /home/user/software/libsvm/ 0 L 1 1 S 0" are all the parameterds needed by Script.java to correctly run "software".

    This command line runs very well when used in the Shell. But I cannot make it work when using :

    Runtime rt = Runtime.getRuntime();
    Process proc = rt.exec(String[]);

    I have already tried to organize this command line in an array of strings but I have many errors. Please, could you help me to organize all these commands and arguments to make my software work ?
    I'm working on this since 4 days, and I'm really desperated...

    Thanks you in advance for your responses/advices


    Nath

  2. #2
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    393
    Rep Power
    10

    Default Re: Problems with Process.exec (long arguments, complex command line)

    Hi nath, welcome to the forums.

    It would be useful to see the errors you are getting as well as any relevant code.
    Please ensure to use the code tags as it will preserve formatting and make things a lot easier to read.

    [code=java]
    YOUR CODE GOES HERE
    [/code]

    Regards.

  3. #3
    nath02 is offline Member
    Join Date
    Sep 2014
    Posts
    2
    Rep Power
    0

    Default Re: Problems with Process.exec (long arguments, complex command line)

    Quote Originally Posted by Ronin View Post
    Hi nath, welcome to the forums.

    It would be useful to see the errors you are getting as well as any relevant code.
    Please ensure to use the code tags as it will preserve formatting and make things a lot easier to read.

    [code=java]
    YOUR CODE GOES HERE
    [/code]

    Regards.
    Hello


    Thank you for your advice. In order to run my program in the good directory, I changed my code like this :

    Java Code:
    String path_software = "/home/user/software/";
     
            String pix = "0 1 0 1 /home/user/LS/LS5QU/ 1000 32 1000 32 10 28 1000 1191 1 1 0 0 0 0 S 25 90 0 0 0 0 T 0 100 1 0.0 1000 /home/tmp/ Z 0 B 0 0 C 0 1 L /home/user/ 0 L 1 1 S 0"; 
            String cmd = "java";
            String mem = " -Xmx1G";
            String path = " -classpath a.jar:b.jar:c.jar:d.jar:. Script_cv";
            String command = cmd + mem + path;
            String script = pix;
            String[] argsP = {command,script};
            System.out.println("Command :" + command);
     
            try {
                //Runtime rt = Runtime.getRuntime();
                //System.out.println("Begin running...");
                //Process proc = rt.exec(command); 
                //Process proc = rt.exec(argsP);
     
                ProcessBuilder pb = new ProcessBuilder(argsP);
                pb.directory(new File(path_software));
     
                Process p = pb.start();
     
                ShowFlux outFlux = new ShowFlux(p.getInputStream());
                ShowFlux errFlux = new ShowFlux(p.getErrorStream());
     
                new Thread(outFlux).start();
                new Thread(errFlux).start();
     
                int exitVal = p.waitFor();
                System.out.println("Wainting over. Process exit Value :" + exitVal);
            } catch(IOException e){
                e.printStackTrace();
            } catch (InterruptedException e){
                e.printStackTrace();
            }
     
        }
    Unfortunately, I get this error :

    Directory of software : /home/user/software/
    Command :java -Xmx1G -classpath a.jar:b.jar:c.jar:d.jar:. Script_cv
    Arguments software (script) : 0 1 0 1 /home/user/LS/LS5QU/ 1000 32 1000 32 10 28 1000 1191 1 1 0 0 0 0 S 25 90 0 0 0 0 T 0 100 1 0.0 1000 /home/tmp/ Z 0 B 0 0 C 0 1 L /home/user/ 0 L 1 1 S 0
    java.io.IOException: Cannot run program "java -Xmx1G -classpath a.jar:b.jar:c.jar:d.jar:. Script_cv" (in directory "/home/user/software"): error=2, No file or repertory of this type (Aucun fichier ou dossier de ce type)

    at java.lang.ProcessBuilder.start(ProcessBuilder.java :1048)u very much


    Does someone have an idea or a solution ?


    Nath
    Thank yo

  4. #4
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    393
    Rep Power
    10

    Default Re: Problems with Process.exec (long arguments, complex command line)

    Nath,

    The application is looking in the wrong directory. Try using the complete filepath for the variable path_software.

    Regards.

Similar Threads

  1. What are command-line arguments?
    By Kratos321 in forum New To Java
    Replies: 12
    Last Post: 03-18-2012, 11:59 PM
  2. command line arguments
    By shruthichandru in forum New To Java
    Replies: 11
    Last Post: 11-20-2010, 03:02 AM
  3. command line arguments
    By evermore in forum New To Java
    Replies: 5
    Last Post: 03-28-2010, 06:08 AM
  4. arguments in command-line
    By girlet18 in forum New To Java
    Replies: 2
    Last Post: 01-21-2010, 03:05 PM
  5. Command line arguments help
    By may88 in forum New To Java
    Replies: 8
    Last Post: 12-08-2009, 02:20 PM

Posting Permissions

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