...
> Can anyone provide me some hints on calling a "*.bat" file from a
>java program.I have a .bat file, in which I am calling another third
>party java class which is there in a jar file.
Why not call the class directly from Java code?
Simply ensure the class is on the classpath of
the first application, then..
>I need to call this ... from another java program and provide
>the three parameters at run time.
..the class can be loaded by importing it and
creating an instance.
Other strategies (assuming the second jar is not on
the original app's classpath) are to use an URLClassLoader,
pointing to the new Jar.
If all else fails (class not in Jar/in default package/
not known till after start-up), you might need to
'stoop' to using reflection - in order to load it.
>any ideas?
Capitalise the first letter of every sentence and
question, and also exclude '*' characters from
the subject line, as they might be mistaken for
(edited) swear words.

Signature
Andrew Thompson
http://www.athompson.info/andrew/
vysh - 18 May 2007 07:56 GMT
> ..
>
[quoted text clipped - 31 lines]
>
> Message posted via JavaKB.comhttp://www.javakb.com/Uwe/Forums.aspx/java-general/200705/1
In that case how to pass the parameters?
import cm.xx.cc.vv.MyClass
....
.....
MyClass x=new MyClass()..//here where to pass my parameters?
Andrew Thompson - 18 May 2007 09:52 GMT
(run class directly from Java code)
>In that case how to pass the parameters?
>import cm.xx.cc.vv.MyClass
>....
>.....
>MyClass x=new MyClass()..//here where to pass my parameters?
Do you have the source to cm.xx.cc.vv.MyClass ?
If so, the answer is simple.
Do it exactly* how it is done inside the main()
of cm.xx.cc.vv.MyClass. * Adapting the sections
used to collect and parse the command-line
arguments, since you can (or at least might -
for simplicity) hard code them directly in the
invoking source.

Signature
Andrew Thompson
http://www.athompson.info/andrew/
Lew - 18 May 2007 13:29 GMT
vysh wrote:
> (run class directly from Java code)
>> In that case how to pass the parameters?
>> import cm.xx.cc.vv.MyClass
>> ....
>> .....
>> MyClass x=new MyClass()..//here where to pass my parameters?
This is very basic Java knowledge.
Read these, and the rest of the tutorial:
<http://java.sun.com/docs/books/tutorial/java/javaOO/arguments.html>
<http://java.sun.com/docs/books/tutorial/java/javaOO/objectcreation.html>

Signature
Lew
vysh - 21 May 2007 05:43 GMT
> vysh wrote:
>
[quoted text clipped - 13 lines]
> --
> Lew
hi lew,
I know it is something very basic.But I have told before that i dont
have the source code for that class.The only thing I know is, if I
call the class and give a couple of parameters(only as command line
parameters) i will get some specific result.I dont know any of the
methods inside dealing with that class.any ideas?
thanks,
vysh
vysh - 21 May 2007 05:47 GMT
> (run class directly from Java code)
>
[quoted text clipped - 5 lines]
>
> Do you have the source to cm.xx.cc.vv.MyClass ?
You guessed it right.I dont have the source code!
The only thing I know is that I can pass a couple of paramters as
command line to that class.Thats it!.So only i have gone for the bath
file idea.
any views?
Patricia Shanahan - 18 May 2007 13:31 GMT
...
> In that case how to pass the parameters?
> import cm.xx.cc.vv.MyClass
> ....
> .....
> MyClass x=new MyClass()..//here where to pass my parameters?
How about this? If you run a Jar, that does not immediately create a
class instance. It calls the main method, as a static method, with an
array of String as parameter:
MyClass.main( new String[]{param1,param2} );
However, whether this strategy works depends on the design of the
package structures. Any overlap between the Jar and the calling program,
such as two classes with the same name without package declarations,
could cause confusion.
Patricia
vysh - 21 May 2007 05:55 GMT
> ...
>
[quoted text clipped - 16 lines]
>
> Patricia
Its a good idea patricia.But still there is a huddle.In my application
I am not using any log's.I mean something like log4j, and this
particular class uses log4j.The requirement for the class is that,it
should be called as-----java -Dlog4j.configuration=filename par1 par2.
So if i am calling the main as you suggested,I wont be able to
initialize this log file.So the only way through is a batch file.
any ideas?
thanks for your comments,
vysh
...
> Can anyone provide me some hints on calling a "*.bat" file from a
>java program.
I think it is preferable to avoid the .bat file altogether,
but keep forgetting to mention that in addition to the
strategies I have already outlined, you might also use
one of the java.lang.Runtime.exec() method variants to
invoke the JVM (passing the arguments as it is invoked),
..or call the bat file.

Signature
Andrew Thompson
http://www.athompson.info/andrew/
squirrel - 20 May 2007 16:36 GMT
> ..
>
[quoted text clipped - 12 lines]
>
> Message posted viahttp://www.javakb.com
And if the third application has output on default stream, in java is
System.out, you need to collect them, it is necessary to make the
third application running correctly.
vysh - 21 May 2007 05:56 GMT
> > ..
>
[quoted text clipped - 16 lines]
> System.out, you need to collect them, it is necessary to make the
> third application running correctly.
It does!.actually the end out put is a .text file.
thanks,
vysh
vysh - 21 May 2007 08:25 GMT
hi all,
Thanks a lot for all your comments.
yeh! I am done with that problem!
I have called tha Batch file using the Runtime() method and passed the
parameters.Now its working fine.
Thanks,
vysh
vysh - 21 May 2007 05:50 GMT
> ..
>
[quoted text clipped - 7 lines]
> invoke the JVM (passing the arguments as it is invoked),
> .or call the bat file.
yes!.But i have tried to invoke a test.bat file using the
Runtime.getRuntime.exec() method.It dosen't work!.Here is my code.
String str=s[0];
String batfile="test.bat";
String cmd="./"+batfile+" "+str;
try
{
Process p=Runtime.getRuntime().exec(cmd);
p.waitFor();
}catch(Exception e){
System.out.println(e.getMessage());
> --
> Andrew Thompsonhttp://www.athompson.info/andrew/
>
> Message posted viahttp://www.javakb.com