How to invoke and pass arguments to a batch file from a java code

Hi

I have a batch file (marcxml.bat) which has the following excerpt :

@echo off

if x==%1x goto howto

java -cp C:\Downloads\Marcxml\marc4j.jar; C:\Downloads\Marcxml\marcxml.jar; %1 %2 %3

goto end

I'm calling this batch file from a java code with the following line of code:

Process p = Runtime.getRuntime().exec("cmd /c start C:/Downloads/Marcxml/marcxml.bat");

so ,that invokes the batch file.Till that point its ok.

since the batch file accpets arguments(%1 %2 %3) how do i pass those arguments to the batch file from my code ...?

%1 is a classname : for ex: gov.loc.marcxml.MARC21slim2MARC

%2 is the name of the input file for ex : C:/Downloads/Marcxml/source.xml

%3 is the name of the output file for ex: C:/Downloads/Marcxml/target.mrc

could someone help me...

if i include these parameters too along with the above line of code i.e

Process p = Runtime.getRuntime().exec("cmd /c start C:/Downloads/Marcxml/marcxml.bat gov.loc.marcxml.MARC21slim2MARC C:\\Downloads\\Marcxml\\source.xml C:\\Downloads\\Marcxml\\target.mrc") ;

I get the following error :

Exception in thread main java.lang.Noclassdef foundError: c:Downloads\marcxml\source/xml

could some one tell me if i'm doing the right way in passing the arguments to the batch file if not what is the right way?

[1385 byte] By [justunme1a] at [2007-11-27 9:55:40]
# 1
Why use the batch file at all? You can just call the main method of that jar file directly. I'm assuming you either have the source or an api for the marc4j package that you can reference to find that method, right?
hunter9000a at 2007-7-13 0:25:41 > top of Java-index,Java Essentials,New To Java...
# 2

Your error is not in the

Process p = Runtime.getRuntime().exec("cmd /c start C:/Downloads/Marcxml/marcxml.bat gov.loc.marcxml.MARC21slim2MARC C:\\Downloads\\Marcxml\\source.xml C:\\Downloads\\Marcxml\\target.mrc") ;

line

the error is generated by the

java -cp C:\Downloads\Marcxml\marc4j.jar; C:\Downloads\Marcxml\marcxml.jar; %1 %2 %3

line in bat file.

So, the jar you are trying to run is not finding ("resolving") one of your parameters

pbulgarellia at 2007-7-13 0:25:41 > top of Java-index,Java Essentials,New To Java...
# 3
If i run the batch file from the command line and pass the same parameters as i'm passing in the code it works fine .I'm having the problem only when i'm invoking the batch file from the code...
justunme1a at 2007-7-13 0:25:41 > top of Java-index,Java Essentials,New To Java...