Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

how to pass arguments to a batch file from java code

843798Jul 5 2007 — edited Jul 11 2007
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??

Message was edited by:
justunme1
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 8 2007
Added on Jul 5 2007
3 comments
1,384 views