Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Calling a Batch file from Java using the exec command.

Reply
Thread Tools

Calling a Batch file from Java using the exec command.

 
 
jds
Guest
Posts: n/a
 
      07-02-2003
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.
 
Reply With Quote
 
 
 
 
dhek bhun kho
Guest
Posts: n/a
 
      07-02-2003
http://www.velocityreviews.com/forums/(E-Mail 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=bat...=Google+zoeken

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

greets.
Bhun.

 
Reply With Quote
 
 
 
 
pizzapie pizzapie is offline
Junior Member
Join Date: Sep 2010
Posts: 1
 
      09-11-2010
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
 
Reply With Quote
 
Nitin Yadav Nitin Yadav is offline
Junior Member
Join Date: Oct 2011
Posts: 2
 
      10-03-2011
Quote:
Originally Posted by pizzapie View Post
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...
 
Reply With Quote
 
Nitin Yadav Nitin Yadav is offline
Junior Member
Join Date: Oct 2011
Posts: 2
 
      10-03-2011
Hey, Please can you explain it with an example...please...please...please...
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Net::SSH.exec Using the "exec" method interactively Guillermo Riojas Ruby 0 11-26-2010 05:17 PM
Runtime.Exec and windows batch file MMilkin@gmail.com Java 5 10-18-2006 12:09 AM
Runtime.exec(String[]) Doesn't Always Work, bBut Runtime.exec(String) Does Hal Vaughan Java 11 05-22-2006 04:49 PM
Calling a batch file from IE using asp and vbscript Mark C. ASP General 14 01-25-2005 09:35 AM
Backup Exec 9.1: The Backup Exec job engine system service is not responding Christian Falch Computer Support 1 06-23-2004 02:22 AM



Advertisments