Results 1 to 6 of 6

Thread: Problem launching .sh from java program

  1. #1
    Join Date
    Dec 2009
    Posts
    204

    Problem launching .sh from java program

    Hi,
    I have a problem running a script. Sh from a Java program. It works well for a start ls:
    Code:
    Process chk = Runtime.getRuntime().exec("ls");
    but not to start my script:
    Code:
    Process chk = Runtime.getRuntime().exec(".. / shell / verif_reception / verif_fic_reception.sh");
    What is the problem? Why is it not executing the program. Please help.
    Last edited by Ash maker; 16-01-2010 at 12:33 PM.

  2. #2
    Join Date
    May 2008
    Posts
    2,012

    Re: Problem launching .sh from java program

    Hello.
    Try the following code, and if you have problem post back
    Process chk = Runtime.getRuntime().exec("sh-c .. / shell / verif_reception / verif_fic_reception.sh");
    You have not post your complete code, therefore it is diffucult to say weather you have used exception in your code, if you are not used them, I would recommend to use them.

  3. #3
    Join Date
    Dec 2009
    Posts
    204

    Re: Problem launching .sh from java program

    Hello,
    Sorry, I have not used exceptions in my code. When I run my .sh at the prompt, it works fine and nothing appears as if the command returns nothing. I tried what you gave me but it does not works. Here is my code
    Code:
    try
    	      {
    	      	Process ch = Runtime.getRuntime().exec("sh-c .. / shell / verif_reception / verif_fic_reception.sh");
    verif.waitfor();
    		   	
    	      	   
    	    	  / / Redirect standard output to JTexteArea
    	    	  InputStream input = verif.getInputStream();
    			   inputt i;
                while((i = input.read()) != -1)
                {
                    System.out.print((char)i);
                    this.Console.append(Strinputg.valueOf((char)i));
                }
                input.close();
                
                / / Updates the console
                this.Console.repainputt();
             }
             catch(Throwable e)
             {
             	System.out.System.out.println(e)
             }

  4. #4
    Join Date
    May 2008
    Posts
    2,389

    Re: Problem launching .sh from java program

    Hi,
    Try to run your program with a command from the root
    Process chk = Runtime.getRuntime().exec("sh-c usr / local / shell / verif_reception / verif_fic
    See, what is the output of this command in the terminal, if it works there, then it should work well from your java code too. Try the above and if you have any more problems then post back.

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: Problem launching .sh from java program

    Hey,
    Iis it necessary that you indicate the directory where my script will work sh, I think so, you have to do it. There's a method to set the working directory,
    public Process exec (String cmd, String [] envp, File dir)
    throws IOException
    But it is available only for java version greater than 1.3, I do not know what version you are using. If you do not have the latest version of java, then you can download from the sun's official site, it is available there.

  6. #6
    Join Date
    Dec 2009
    Posts
    204

    Re: Problem launching .sh from java program

    Hi,
    Thanks, it works. In fact I have my MODF .sh for it to operate from the directory of my application. I then put in the same directory that my application and I did:
    Process ch = Runtime.getRuntime().exec("verif_fic_reception.sh");
    I think the exec method to set the working directory would be a good solution. I did not had the latest version of java, I downloaded it from the sun. though I had java 5, their latest version is java 6.

Similar Threads

  1. Launching chess program automatically in the Linux Mint?
    By MaHiNo in forum Operating Systems
    Replies: 4
    Last Post: 12-01-2011, 05:51 AM
  2. Problem in using regex in java program.
    By Kasper in forum Software Development
    Replies: 5
    Last Post: 05-03-2010, 05:39 PM
  3. Problem in sending mail - java program
    By ISAIAH in forum Software Development
    Replies: 5
    Last Post: 04-01-2010, 01:11 PM
  4. Link List Example in Java Sample program in Java
    By trickson in forum Software Development
    Replies: 2
    Last Post: 04-08-2009, 08:23 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,058,528.52612 seconds with 17 queries