Results 1 to 3 of 3
- 11-02-2007, 10:50 PM #1
Member
- Join Date
- Oct 2007
- Posts
- 6
- Rep Power
- 0
Running java program with arguments in Unix"
Hi
I am a new newbie to java so pardon if this is too simple for you .
This is my scenario. I have a java program which parses an xml and writes a .dat file. I execute this testparser.java in unix environment like this
java testparser xml1.xml
and it retuns me a .dat file
But my issue is I have to run my parser program for 40 xml files. The requirement is I have to create a script file and possibly with a for loop which will loop through 1-40 xml files and return me the .dat file.
I am really at a loss here. I am new both to Java and Unix
So pls help me out
Thanks in Advance
G
- 11-03-2007, 07:32 AM #2
What about creating a text file which will have your xml files listed in separate lines. As far as i understand your problem, you can modify your program to get this .txt file as an input and loop for all these xml files to generate dat file(s).
- 11-08-2007, 07:01 PM #3
Member
- Join Date
- Nov 2007
- Location
- Singapore
- Posts
- 3
- Rep Power
- 0
You may try the following code:
Java Code:public class TestParser{ public static void main(String[] args){ for(int i=0; i<Integer.parseInt(args[1]); i++) { File file = new File(args[0]+"/filename"+(i+1)+".xml"); doTestParser(file); } } static void doTestParser(File pFile ){ //do something with the xml file } }
You should now execute only one time from the command line, e.g:
/>java Testparser <<file directory>> <<total file>>
Regards,
Putrama
Similar Threads
-
Accessing unix system using java
By abhishek.sinha in forum AWT / SwingReplies: 3Last Post: 06-19-2008, 08:05 AM -
how to run java app on windows in a cron like on unix
By rockie12 in forum Advanced JavaReplies: 7Last Post: 05-23-2008, 01:39 PM -
When to use –client and -server option while running a java program
By Java Tip in forum java.langReplies: 0Last Post: 04-04-2008, 02:49 PM -
Filter a file in java (unix cut command equivalent)
By marcosabel in forum New To JavaReplies: 0Last Post: 02-11-2008, 07:26 PM -
Call a main method from within a running program
By zoe in forum New To JavaReplies: 1Last Post: 08-07-2007, 06:16 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks