Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 10-22-2003, 09:27 AM   #1
LQ Newbie
Registered: Sep 2003
Location: Hyderabad
Distribution: Fedora Core 2
Posts: 10

Rep: Reputation: 0
Command line arguments to java program


I have a java code and want it to accept command line arguments in the form given below

java mybrowser -host <hostip> -port <port> -url <urlname>

but this is interpreted as arguments for java (because of -host etc.) instead of my program and it gives lots of errors for invalid array element access (since I used String [] args in main)

But the same works in Windows. Is there any way to do this in Linux
Old 10-22-2003, 07:39 PM   #2
Senior Member
Registered: Mar 2003
Location: New York, NY
Distribution: Debian Testing
Posts: 1,286

Rep: Reputation: 46
might i ask why u cant just give the options without the '-'?
its realllly not needed, is it?
Old 10-23-2003, 03:24 AM   #3
Registered: Oct 2003
Location: Europe/Sweden
Distribution: RedHat
Posts: 78

Rep: Reputation: 15
I think you have to go for an other java implementation. You usings suns implementation on Linux?

Besides, should "long options" have "--" infront of them anyhow? =)
Maybe this gets parsed to java bin.
Old 10-23-2003, 05:48 AM   #4
Registered: Jun 2003
Location: Alphen ad Rijn -- The Netherlands
Distribution: Fedora Core 2 - Slackware 12
Posts: 119

Rep: Reputation: 15
You must execute the program as follows

java mybrowser 23

In java you could retrieved the arguments as follows:

public static void main (String [] args) {

String hostName = args[0];
String port = args[1];

Java developer

Last edited by jpostma; 10-23-2003 at 05:51 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
alsamixer command line arguments dereko Debian 3 09-29-2008 02:06 PM
Hiding password in Java command line program simon_w Programming 2 05-02-2005 06:01 AM
Awk command-line arguments lowpro2k3 Programming 1 03-28-2005 09:09 PM
number of command line arguments to shell u4u Linux - General 1 03-04-2005 06:09 PM
Help with command line arguments ? synapse Linux - Newbie 2 02-23-2004 02:25 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:56 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration