• Post Reply Bookmark Topic Watch Topic
  • New Topic

unix console, program parameter  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, my first post here, I'd like to say this place is amazing.

I got a problem and I got to say I'm not sure if it is even possible to achieve..
Id like to have a short "script", written in java ( I know there are plenty of languages better suited for this task, still, has to be java), which after giving in command line a parameter to it it will f.e. change an ip..

so, in command line:

linux-host:#myprogramname.java -parameter value

for example:
inux-host:#changeip.java -changeip 10.0.2.99

under -changeip I have made a bash const of "ifconfig". So in reality program will couse "ifconfig eth0 10.0.2.99" and that will change ip on eth0 to given in parameter.


Is it even possible to achieve this? How can I code "parameter" to use it in command line when starting the program?
Eny examples of such usage of java?

Best regards.
 
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to Javaranch.

I don't think I really understood your problem. Can't you use command line parameter option which you can access in your java main method?
 
Wojtek Grycan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mannoj patil wrote:Welcome to Javaranch.

I don't think I really understood your problem. Can't you use command line parameter option which you can access in your java main method?


yes, exactly

paramater is my method which really will be a bash command but thats not important now. I just cant imagine how can I possibly implement "parameter" option...

Like I told earlier, I want to put in a unix console:

compiling:
linux-1# javac myprogramname.java
executing:
linux-1# java myprogramname.class -parameter value

parameter is my implemented method which will work with "value" provided in command line as well.

For example I'll name parameter "ipchange" and will implement under that name bash command of "ifconfig eth0 ", this is what I really want to execute. So by writing in console:

linux-1# java myprogramname.class -ipchange 10.0.0.1
really Ill execute
linux-1# ifconfig eth0 10.0.0.1

I hope this is more clear..


 
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The public static void main(String[] args) gets the command line arguments as a string array. I'd recommend using a command-line option processing library, though, even for relatively simple programs.
 
Wojtek Grycan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote:The public static void main(String[] args) gets the command line arguments as a string array. I'd recommend using a command-line option processing library, though, even for relatively simple programs.


idd, this works well. Just need to specify my own parameter names and hard part is done. Simple socket client-server addition and Ill have my own putty ;P




Best regards.
 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does "idd" mean? Please read this FAQ.
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to JavaRanch

I think this question is too difficult for "beginning" so I shall move it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!