The Artima Developer Community
Sponsored Link

Java Answers Forum
running batch files from java

1 reply on 1 page. Most recent reply: Jul 26, 2004 4:22 AM by Sunitha C S

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
ross klingensmith

Posts: 1
Nickname: kling
Registered: Jul, 2004

running batch files from java Posted: Jul 23, 2004 6:38 PM
Reply to this message Reply
Advertisement
I am a developer who is trying to run batch files from within a java application. As of now, i can get the batch files to run in order like so:

do
{
Process rt;
rt=Runtime.getRuntime().exec( "run.bat "+
strUnits[iIndex]+ ".txt"
+ strUnits[iIndex] )
rt.wait()
iIndex++;
}while(strUnits[iIndex] != null )

However, I am trying to get these batch files to run at the same time (each one can run indefinately).
If i remove the rt.wait(), none of the batch files get called. Is there a way to do this? Possibly with threading (dont know how to use threading if a variable number of threads are used), or is what i am trying to do out of the scope of what java can do?

Thank you for advance for your help


Sunitha C S

Posts: 20
Nickname: sunics
Registered: Dec, 2003

Re: running batch files from java Posted: Jul 26, 2004 4:22 AM
Reply to this message Reply
Hello,

The same code can be used with threads. the following change u need to make.

public class BatchThread extends Thread
{
...
...
...
int val;
public BatchThread(int s)
{ val=s;
}
public void run()
{ Process rt;
rt=Runtime.getRuntime().exec( "run.bat "+
strUnits[val]+ ".txt"
+ strUnits[val] )
}
}

public class theCaller
{....
....
public static void main(String s[])
{ int i=0;
do{ BatchThread t=new BatchThread(i);
t.run();
i++;
}while(i<=strUnits.length)
}
}

good luck....

sunitha

Flat View: This topic has 1 reply on 1 page
Topic: inverse interpolation Previous Topic   Next Topic Topic: problem in threading a server program

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use