|
| |||||||||
| Tags: abstract method, class, exec0, function, java, method, programming language |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| 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();
}
__________________ www.techarena.in |
|
#2
| |||
| |||
| 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. |
|
#3
| |||
| |||
| 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")); Code: java.lang.IllegalThreadStateException: Process Hasn't exited |
|
#4
| |||
| |||
| 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 |
|
#5
| |||
| |||
| 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);
}
}
} |
|
#6
| |||
| |||
| 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();
}
}
} |
![]() |
|
| Thread Tools | Search this Thread |
| |
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 |