Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , , , ,

Sponsored Links



exec() function in java

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 11-03-2010
Member
 
Join Date: Mar 2010
Posts: 186
exec() function in java

Hello,
I want to run a perl script into my java application. For the moment I'm testing with runtime:: exec (). function which is available in java
Here is my code
Code:
       try
        {   
            Runtime rutm = Runtime.getRuntime();
            Process p = rutm.exec("cmd.exe");
            int val = p.exitValue();
            System.out.System.out.println("Process exitValue" + ExitVal);
        } catch (Throwable t)
          {
            t.printStackTrace();
          }
And even that does not work, I have this message. I get an error which running the program, if you have any idea about it , then please let me know. Thanks in advance.
__________________
www.techarena.in
Reply With Quote
  #2  
Old 11-03-2010
Member
 
Join Date: Nov 2009
Posts: 583
Re: exec() function in java

Hello,
I ran your code and it works well with me yet. Are you sure to have access to "cmd.exe" from the directory where you run your application? tries to use this command from a console to check: it seems that Java does not simply find your program. I think you should try to run the program again using an IDE like eclipse and see if the program work, if not then try running with the terminal. Hope this will help you and I guess you got some idea from this.
Reply With Quote
  #3  
Old 11-03-2010
Member
 
Join Date: Dec 2009
Posts: 292
Re: exec() function in java

Hello,
Even I need to run the same command in my program, but it is not working. I did not have access to cmd.exe. Now I test with "ls" or even
Code:
Process p = r.exec (new String [] ( "perl", "", "scrt.pl"));
and I get the following error
Code:
java.lang.IllegalThreadStateException: 
Process Hasn't exited
Any help on this is appreciated, thanks in advance.
Reply With Quote
  #4  
Old 11-03-2010
Member
 
Join Date: Mar 2010
Posts: 186
Re: exec() function in java

Hello,
It is clear, thank you, I really did anything. If not for my problem, it was enough to make a waitfor(), which seems a little strange because it seems to execute, in fact have one function and I made a small but good execution. Otherwise, I now also manages the flow. Thanks again for your help and if you know any alternate method for doing the same then I am the interested one here.
__________________
www.techarena.in
Reply With Quote
  #5  
Old 11-03-2010
Member
 
Join Date: Nov 2009
Posts: 347
Re: exec() function in java

Hello,
Have a look at the following code

Code:
   public class DoRuntime {
     public static void main(String args[]) throws IOException {

       if (args.length <= 0) {
         System.err.println("Need command to run");
         System.exit(-1);
       }

       Runtime rntm = Runtime.getRuntime();
       Process process = rntm.exec(args);
       InputStream inp = process.getInputStream();
       InputStreamReader inpstr = new InputStreamReader(inp);
       BufferedReader buff = new BufferedReader(inpstr);
       String line;

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

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

     }
    }
Reply With Quote
  #6  
Old 11-03-2010
Member
 
Join Date: Nov 2009
Posts: 335
Re: exec() function in java

Hello,
Alternatively even this program can help you , take a look at it
Code:
import java.io.IOException; 
public class runexe{
    public static void main(String[] args){
    try
    {
    Process p = Runtime.getRuntime()
.exec("notepad.exe");
    }catch (IOException e)
    {
     e.printStackTrace();
    }
  }
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "exec() function in java"
Thread Thread Starter Forum Replies Last Post
Fix Microsoft Excel function Exec Error Sachi Trivedi MS Office Support 5 2 Weeks Ago 12:51 PM
Firefox 3.6.18 giving JAVA SCRIPT EXE error “Exc in ev handl: TypeError: this.oRoot.enable is not a function” Katyayani Technology & Internet 10 31-12-2011 08:41 AM
Periodic function in java Shaan12 Software Development 4 20-07-2010 02:11 PM
What is the meaning of function($) in java? Steadfast Software Development 5 22-02-2010 09:08 PM
How to disable exec() function in PHP Japheth Software Development 3 04-05-2009 10:38 AM


All times are GMT +5.5. The time now is 12:07 PM.