Results 1 to 11 of 11
- 01-24-2012, 07:08 PM #1
Member
- Join Date
- Nov 2009
- Posts
- 7
- Rep Power
- 0
Java from console with parameters... with inetrnal parameters
Hi,
I am a beginner in Java, and I have a problem.
I have a java program, which is running in console.
When I run it as "java -cp ...., program runs and waits for my internal command with parameters like this command_name -param_name param.
How to run this program from console with initial internal command with internal parameters, something like this way :
java -cp ..... command_name -param_name param ??
As I showed it doesnt work.
Thanks in advance
- 01-24-2012, 07:11 PM #2
Re: Java from console with parameters... with inetrnal parameters
Not sure what you're asking. -cp sets the class path if you are using external libraries. If you just want to run your java program, do something like this
java MyProgram
... Assuming you have compiled it and are in the same directory as the resulting class file.
- 01-24-2012, 07:17 PM #3
Re: Java from console with parameters... with inetrnal parameters
I'm also not sure what you're asking, but i think its how to add parameters to the command line?
If that is the case, your main function is where you want to look. If i have this code -
args contains all of the parameters passed after the file name, separated by spaces.Java Code:public static void main(String[] args) { ... }
So if my class is called HelloWorld and i run "java HelloWorld this is a test" then the values of args would be -
Java Code:args[0] = "this" args[1] = "is" args[2] = "a" args[3] = "test"
- 01-24-2012, 07:18 PM #4
Member
- Join Date
- Nov 2009
- Posts
- 7
- Rep Power
- 0
Re: Java from console with parameters... with inetrnal parameters
Thanks, but I am not asking about it. I want to run "java MyProg internal_prog_command -internal_param_nam param" from the console.
edit:
Yes I know, but inside my program I have -name_of_parameter and value_of_parameter...
Sorry, but I am not native english.
Inside my program i put commands the way like this.... command -option parameter...
How to put it from console when starting a program ??Last edited by metoda; 01-24-2012 at 07:24 PM.
- 01-24-2012, 07:27 PM #5
Re: Java from console with parameters... with inetrnal parameters
The only way that i know of to interact with your program from the console is how i have shown above. Passing in strings in the args parameter. You can then use their values to run your commands? Maybe it would help if you posted some of your code to show us exactly what you're doing with these commands?
- 01-24-2012, 07:43 PM #6
Member
- Join Date
- Nov 2009
- Posts
- 7
- Rep Power
- 0
Re: Java from console with parameters... with inetrnal parameters
When I start the program, it waits for my command. I put this: joinN -port 8080 -bootstrap 192.168.1.101:4242... and it works
When I run this externally from console java -cp .;build\classes;config;lib\log4j.jar de.uniba.wiai.lspi.chord.console.Main joinN -port 8080 -bootstrap 192.168.1.101:4242 it doesn't work. It only gets command_name "joinN" but without -options ... Why ??
- 01-24-2012, 07:54 PM #7
Re: Java from console with parameters... with inetrnal parameters
Is this code you're writing or some other program you're trying to run?
If you want all of that to go in as one string, you'd have to enclose them in quotation marks -
java -cp .;build\classes;config;lib\log4j.jar de.uniba.wiai.lspi.chord.console.Main "joinN -port 8080 -bootstrap 192.168.1.101:4242"
- 01-24-2012, 08:19 PM #8
Member
- Join Date
- Nov 2009
- Posts
- 7
- Rep Power
- 0
Re: Java from console with parameters... with inetrnal parameters
This is an open source program OpenChord, which implements Chord algorithm in DHT overlay network.
It uses sockets. I need to open it about twenty times in separate consoles.
Whent I open first instance manually and put internal command "joinN" to prepare the network, it works.
When I open it form console with this internal command "java -cp ...classes MyProgram joinN" it also works.
When I open second instance and put internal command "joinN -port 8080 -bootstrap 192.168.0.1:4242" it aso works fine.
But when I open it from console with internal command "java -cp ...classes... MyProgram joinN -port 8080 -bootstrap 192.168.0.1:4242", it does not work, it behaves as only parameter "joinN" is seen.
edit:
Ok, Your sollution with " seems to be correct. Thanks a lot.Last edited by metoda; 01-24-2012 at 08:24 PM.
- 01-24-2012, 09:30 PM #9
Member
- Join Date
- Nov 2009
- Posts
- 7
- Rep Power
- 0
Re: Java from console with parameters... with inetrnal parameters
Ok, I have another question, as is works fine.
Now, I am running this application from console with internal command with -options, but i want also include next command within this.
Between this two internal commands the press Enter button is needed. Do You have any sugestion ??
- 01-24-2012, 09:47 PM #10
Re: Java from console with parameters... with inetrnal parameters
These questions would be better in a forum for the OpenChord application as i have no idea how they programmed it to work.
However, just guessing, you can try passing two commands to the class separated by a space.
java -cp .;build\classes;config;lib\log4j.jar de.uniba.wiai.lspi.chord.console.Main "joinN -port 8080 -bootstrap 192.168.1.101:4242" "second command"
- 01-24-2012, 10:02 PM #11
Member
- Join Date
- Nov 2009
- Posts
- 7
- Rep Power
- 0
Similar Threads
-
how to pass parameters from a method to another which accepts to parameters?possible?
By amrmb09 in forum Advanced JavaReplies: 5Last Post: 11-21-2010, 02:08 PM -
Count the numbers of parameters programmatically that a method has in JAVA?
By rsegecin in forum Advanced JavaReplies: 2Last Post: 10-24-2010, 04:34 PM -
2 import.java.io.*; and assigning parameters
By Shaggx in forum New To JavaReplies: 1Last Post: 02-02-2010, 08:00 PM -
Netware: JAVA.NLM Version 1.31h Parameters
By Larry Mateo in forum New To JavaReplies: 0Last Post: 03-20-2008, 11:34 PM -
Help with parameters values in java
By coco in forum New To JavaReplies: 1Last Post: 07-31-2007, 08:14 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks