Calling a Batch file from Java using the exec command.

J

jds

I am trying to call a batch file from java and expect the batch file
to be executed, but the exec command just comes back without doing
anything. I am working on Windows2000 jdk1.3.1_03. I am truly baffled-
has to be something elementary that I am missing here. Any input will
be helpful.

Thanks,

jds.

1. Here is the test program test.java
---------------------
import java.io.*;
class test{

public static void main(String args[])
{
try
{
System.out.println("Running the batch script");
Runtime.getRuntime().exec("test.bat");
System.out.println("Finished running the batch script");
}
catch(Exception e) {
System.out.println("Error creating the FileInfo panel: " +
e);
e.printStackTrace();
}
}
}
---------------------

2. Here is the result of the java run
C:\>javac test.java
C:\>c:\jdk1.3.1_03\bin\java.exe -classpath . test
Running the batch script
Finished running the batch script

* No notepad was launched

3. Here is test.bat
---------------------
echo "testing"
echo "testing again"
CALL notepad
--------------------
3. Here is the output of test.bat
C:\>test.bat
C:\>echo "testing"
"testing"
C:\>echo "testing again"
"testing again"
C:\>CALL notepad
C:\>

* Notepad was launched.
 
D

dhek bhun kho

(e-mail address removed) (jds), Wed, 02 Jul 2003 13:29:21 -0700:
I am trying to call a batch file from java and expect the batch file
to be executed, but the exec command just comes back without doing
anything. I am working on Windows2000 jdk1.3.1_03. I am truly baffled-
has to be something elementary that I am missing here. Any input will
be helpful.

http://groups.google.nl/groups?q=batch+exec+java&ie=UTF-8&oe=UTF-8&hl=nl&btnG=Google+zoeken

I think you're path settings are wrong. (just see the previous posts)

greets.
Bhun.
 
Joined
Sep 11, 2010
Messages
1
Reaction score
0
hey you guys!! i fount an amazing new way to wait for the thread to stop by itself :)

do this:
Code:
Process process = ...
process.waitFor(); // waits for it to terminate
 
Joined
Oct 3, 2011
Messages
2
Reaction score
0
hey you guys!! i fount an amazing new way to wait for the thread to stop by itself :)

do this:
Code:
Process process = ...
process.waitFor(); // waits for it to terminate

Hey, Please can you explain it with an example..please...please...please...:)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top