Results 1 to 3 of 3
  1. #1
    gvi
    gvi is offline Member
    Join Date
    Oct 2007
    Posts
    6
    Rep Power
    0

    Default 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

  2. #2
    JavaBean's Avatar
    JavaBean is offline Moderator
    Join Date
    May 2007
    Posts
    1,270
    Rep Power
    9

    Default

    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).

  3. #3
    made.putrama is offline Member
    Join Date
    Nov 2007
    Location
    Singapore
    Posts
    3
    Rep Power
    0

    Default

    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

  1. Accessing unix system using java
    By abhishek.sinha in forum AWT / Swing
    Replies: 3
    Last Post: 06-19-2008, 08:05 AM
  2. how to run java app on windows in a cron like on unix
    By rockie12 in forum Advanced Java
    Replies: 7
    Last Post: 05-23-2008, 01:39 PM
  3. Replies: 0
    Last Post: 04-04-2008, 02:49 PM
  4. Filter a file in java (unix cut command equivalent)
    By marcosabel in forum New To Java
    Replies: 0
    Last Post: 02-11-2008, 07:26 PM
  5. Replies: 1
    Last Post: 08-07-2007, 06:16 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •