 |
Author |
Topic: pass variables via command line? (Read 1844 times) |
|
sspboyd
|
pass variables via command line?
« on: Jul 21st, 2004, 12:06am » |
|
I have a program that reads colour palettes from large images and I like to run it from the command line rather then via processing. Is it possible to pass a variable to an exported sketch via the command line? eg: /usr/bin/java -myVar="neon.jpg" -Xms512m -Xmx512m -classpath .:./rc5.jar BApplet rc5 Or I guess even better would be the ability to read a prefs file. (thinking outloud now, I guess I could just specify a text file to be read and parse it for the vars I want). That would be much easier than recompile/export it each time I want to change the source image.
|
gmail.com w/ sspboyd username
|
|
|
sspboyd
|
Re: pass variables via command line?
« Reply #2 on: Jul 21st, 2004, 6:11pm » |
|
I have started using a text file to store the vars I want to use. Works really well. The first lines of the text file contain just one word or number each. I am using it as such: Code:String prefs[] = loadStrings("http://127.0.0.1/p5/bm3/prefs.txt"); // String Value fn=prefs[1]; // Int values divW=toInt(prefs[2]); divH=toInt(prefs[3]); minLen=toInt(prefs[4]); pxSkip=toInt(prefs[5]); |
| I have not figured out yet how to use this method to set boolean values though. Any ideas? steve
|
gmail.com w/ sspboyd username
|
|
|
TomC
|
Re: pass variables via command line?
« Reply #3 on: Jul 21st, 2004, 6:26pm » |
|
I'm guessing there isn't a toBoolean function in the processing API, so you'll have to turn to the Java API to help you. There are 2 choices - use String.equals() or use Boolean.getBoolean(). Code: String yes = "true"; String no = "anythingButTrue"; println(yes); println(no); boolean y1 = Boolean.getBoolean(yes); boolean n1 = Boolean.getBoolean(no); println(y1); println(n1); boolean y2 = yes.equals("true"); boolean n2 = no.equals("true"); println(y2); println(n2); |
|
|
|
|
|
sspboyd
|
Re: pass variables via command line?
« Reply #4 on: Jul 21st, 2004, 6:40pm » |
|
very cool. thanks. I didn't know about those.
|
gmail.com w/ sspboyd username
|
|
|
fjen
|
Re: pass variables via command line?
« Reply #5 on: Jul 24th, 2004, 1:17pm » |
|
or ... to shorten things do like this: Code: String arg = "0"; // 1 for true, anything else for false boolean t_or_f = arg == "1" ? true : false; println(t_or_f); |
|
|
|
|
|
fry
|
Re: pass variables via command line?
« Reply #6 on: Jul 24th, 2004, 2:53pm » |
|
the "official" way to parse a boolean in java is: booleab b = new Boolean(theString).booleanValue(); yech. megabucket will have toBoolean(), and you can also cast strings to booleans, so: boolean b = toBoolean(theString); and boolean b = boolean(theString); will both be valid in the next release. also, args[] will be an array inside your applet that magically reads all the command line args for you. so when you type java PApplet MySketch apple bear cat the args[] variable will contain: { "apple", "bear", "cat" } also helpful for reading prefs is the java "Properties" class, in java.util. it makes it easy to read in a file full of someattribute=somevalue it's how pde.properties is (at least pre-megabucket) handled, for instance.
|
|
|
|
|