For Programmers: Free Programming Magazines  


Home > Archive > Java Help > August 2005 > Batch file params









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Batch file params
iblamemicrosoft@gmail.com

2005-08-27, 7:56 am

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

2005-08-27, 7:56 am

On 27 Aug 2005 04:40:52 -0700, iblamemicrosoft@gmail.com wrote:

> 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...a.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

--
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

2005-08-27, 7:56 am

Andrew Thompson wrote:
> On 27 Aug 2005 04:40:52 -0700, iblamemicrosoft@gmail.com wrote:
>
[color=darkred]
[color=darkred]
> 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...va.html#options
http://java.sun.com/j2se/1.5.0/docs...tml#getProperty(java.lang.String)
http://java.sun.com/j2se/1.5.0/docs...tem.html#getenv(java.lang.String)

Tom Hawtin
--
Unemployed English Java programmer
http://jroller.com/page/tackline/
Andrew Thompson

2005-08-27, 9:58 pm

On Sat, 27 Aug 2005 13:51:40 +0100, Thomas Hawtin wrote:

> 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).

--
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

2005-08-29, 7:02 pm

On 27 Aug 2005 04:40:52 -0700, iblamemicrosoft@gmail.com wrote or
quoted :

>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
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com