Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-15-2008, 07:59 PM
Member
 
Join Date: Feb 2008
Posts: 2
vipvan2000 is on a distinguished road
Parsing Argument Values
Java Gurus,
Need some help here

We use command line scripts to pass values like

java submit <input_file=test1> <output_dir=dir_name>

I have a need to pass the argument values to another program. How do I parse these values.
Sorry if it was asked earlier but I am a little new to Java.

Thanks in advance
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 02-17-2008, 03:41 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
Code:
import java.util.Arrays; public class Test { public static void main(String[] args) { // <input_file=test1> <output_dir=dir_name> // The vm didn't like a left bracket so I did this: // java Test "<input_file=test1> <output_dir=dir_name>" System.out.printf("args = %s%n", Arrays.toString(args)); String inputPath = "", outputPath = ""; String[] s = args[0].split("\\s"); System.out.printf("s = %s%n", Arrays.toString(s)); if(s.length == 2) { inputPath = parse(s[0]); outputPath = parse(s[1]); } System.out.println("inputPath = " + inputPath); System.out.println("outputPath = " + outputPath); } private static String parse(String s) { int start = s.indexOf("=")+1; int end = s.indexOf(">"); return s.substring(start, end); } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Command line argument denisatandi New To Java 3 06-15-2008 08:59 AM
Accessing boolean Values of another values in one class. a_iyer20 Advanced Java 4 04-15-2008 03:04 PM
How to resolve Constructor argument in Spring Java Tip Java Tips 0 03-29-2008 02:43 PM
Parsing Argument Values vipvan2000 New To Java 1 03-06-2008 01:01 PM
How to resolve Constructor argument in Spring JavaBean Java Tips 0 09-26-2007 10:34 PM


All times are GMT +3. The time now is 10:48 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org