This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Java in General and the fly likes How to wrap java programs in cmd.exe and bash? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to wrap java programs in cmd.exe and bash?" Watch "How to wrap java programs in cmd.exe and bash?" New topic
Author

How to wrap java programs in cmd.exe and bash?

Siegfried Heintze
Ranch Hand

Joined: Aug 11, 2000
Posts: 388
I have a groovy program that needs to know the number of args:



Here is the bat file I use to call it and it is not working.


Here is the bash file I use to call it and it is not working.


The problem is that args.size() always returns the same value regardless of how many arguments I pass to main. The solution is to manually set up the class path each time and abandon the bat and bash scripts.

Is there a way to write my bash and bat files so they are sensitive to the number of arguments? I am posting this here in the java forum because I don't believe this problem is specific to groovy.

Thanks,
Siegfried
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39478
    
  28
Don't know, but this is too difficult for "beginning", so I shall move this thread.
Siegfried Heintze
Ranch Hand

Joined: Aug 11, 2000
Posts: 388
Wow! No reply in a while. Does this mean it is not possible? I'm going to try cross posting in www.unix.com concerning bash. I'm not sure where to solicit help with cmd.exe.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19723
    
  20

.cmd file:$* may work in Unix but I'm not really sure.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Siegfried Heintze
Ranch Hand

Joined: Aug 11, 2000
Posts: 388
See http://www.unix.com/shell-programming-scripting/148666-how-make-bash-wrapper-java-groovy-program-variable-length-arguments-lists.html for the unix syntax.

Thanks!
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19723
    
  20

Thanks for sharing that!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to wrap java programs in cmd.exe and bash?