LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

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

Rep: Reputation: 0
Command line arguments to java program


Hi

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

javac mybrowser.java
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
Thanks
Majjj
 
Old 10-22-2003, 07:39 PM   #2
h/w
Senior Member
 
Registered: Mar 2003
Location: New York, NY
Distribution: Debian Testing
Posts: 1,286

Rep: Reputation: 45
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
worldmagic
Member
 
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
jpostma
Member
 
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 www.abnamro.nl 23

In java you could retrieved the arguments as follows:

public static void main (String [] args) {

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

Johannes
Java developer

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


Reply


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


All times are GMT -5. The time now is 01:19 PM.

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