Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / August 2005

Tip: Looking for answers? Try searching our database.

Batch file params

Thread view: 
iblamemicrosoft@gmail.com - 27 Aug 2005 12:40 GMT
I know how in html files you can simply go:

<param name="number" value="1">

but how can you replicate this in a batch file?  Any help would be
appreciated.
Andrew Thompson - 27 Aug 2005 13:01 GMT
> I know how in html files you can simply go:
>
> <param name="number" value="1">

For an applet?  Yes.

> but how can you replicate this in a batch file?  

For an applet?  You can't (at least not easily).

For an application, you can provide arguments on the
command line when you invoke Java, like..

java TheMainClass arg1 arg2 arg3

For more information on the 'java' command, check the JavaDocs
<http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/java.html#synopsis>

Once you can start your Java application from the command
line.  You can put that command in a .bat file and it should
work just fine to launch your application with the arguments
at the end of the 'java' command.

HTH

Signature

Andrew Thompson
physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
"Come on boys, let's push it hard.."
P.J. Harvey 'Victory'

Thomas Hawtin - 27 Aug 2005 13:51 GMT
>>I know how in html files you can simply go:
>>
>><param name="number" value="1">

>>but how can you replicate this in a batch file?  

> For an application, you can provide arguments on the
> command line when you invoke Java, like..
>
> java TheMainClass arg1 arg2 arg3

From a programmer point of view it tends to be easier to pass arguments
as properties. It's also a handy technique if you have lots of classes
with main methods and your IDE can set properties for all of them.

java -Dnumber=1 -jar MyApp

        String number = System.getProperty("number");

In 1.0 and from 1.5 you can also read environment variables through
System.getenv.

#!/bin/bash
export MYAPP_NUMBER=1
java -jar MyApp

        String number = System.getenv("MYAPP_NUMBER");

http://java.sun.com/j2se/1.5.0/docs/tooldocs/solaris/java.html#options
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html#getProperty(java.l
ang.String
)
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html#getenv(java.lang.String)

Tom Hawtin
Signature

Unemployed English Java programmer
http://jroller.com/page/tackline/

Andrew Thompson - 27 Aug 2005 14:12 GMT
> java -Dnumber=1 -jar MyApp
>
>          String number = System.getProperty("number");

Good point Thomas.  There are better ways to do what
the OP requires.  And properties (for one) more closely
fits the requirements in being able to tie values to names.  

I always consider it rather fragile to depend on a
certain parameter order using the 'args' (as I
demonstrated initially).

Signature

Andrew Thompson
physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
"..When after all, it was you and me."
The Rolling Stones 'Sympathy For The Devil'

Roedy Green - 29 Aug 2005 22:49 GMT
>but how can you replicate this in a batch file?  Any help would be
>appreciated.

You can set parms in the environment or set system parms on the
command line.

See http://mindprod.com/jgloss/set.html
http://mindprod.com/jgloss/properties.html
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.