Command line parameters

195 views
Skip to first unread message

Frank Vizza

unread,
Jul 8, 2018, 1:57:21 PM7/8/18
to DroidScript
Is there a way to pass command line parameters to a droidscript program? I can call droidscript programs from a shell command line, but have no method to pass command line parameters.

alex.symbroson

unread,
Jul 8, 2018, 3:30:50 PM7/8/18
to DroidScript
I dont think that you'll be able to access the shell arguments in the DroidScript program. However it may also depend on how you uae DS in shell. Could you explain how you've done it?

Generally the java side which executes the JS code would have to read the arguments and pass it as variable to your code. I'm not sure wether that's the case

alex.symbroson

unread,
Jul 8, 2018, 4:36:11 PM7/8/18
to DroidScript
By the way it makes much more sense to define some boolean or inter flags or a string list of 'options' in your code instead if using command line arguments. These are commonly used for compiled languages because you can not modify the code as easy as interpreted ones cauz you need the compiler, libraries etc. - you don't have any of these problems in JS.

Frank Vizza

unread,
Jul 8, 2018, 4:58:17 PM7/8/18
to DroidScript
I,am,using droidDb. From a form field, I am able to set a value for a variable, then execute that variable through droidDb using a SHELL command.

I can use android commands like "am start" or more UNIX like comman's like dir /sys/img/* > /storage/emulated/0/download/xx.txt

I have written and called an android program com.photoresizer. I have hardcover a predefined target file and predefined resolution. It would be useful if I could set command line parameters.

The following is my example :


var infile = "/sdcard/download/.22.jpg";

function OnStart()
{
lay = app.CreateLayout( "linear", "VCenter,FillXY" );
img1 = app.CreateImage( infile );
lay.AddChild( img1 );
img1.Hide();

var aw = img1.GetAbsWidth();
var ah = img1.GetAbsHeight();
var awah = (ah/aw) * 480;

if(aw > 480) {
img2 = app.CreateImage(null,480,awah,"px");
lay.AddChild(img2);
img2.DrawImage(img1,0,0,1,1);
img2.Hide();
app.AddLayout( lay );
img2.Save(infile);
app.Exit();
} else app.Exit( );
}

Frank Vizza

unread,
Jul 8, 2018, 5:02:53 PM7/8/18
to DroidScript
What do,you mean when you say string list of options?

I am relatively new to DroidScript, but have experience with compiled languages.

Steve Garman

unread,
Jul 8, 2018, 5:22:02 PM7/8/18
to DroidScript
You cannot read arguments sent with a shell command to your app. There is no available equivalent of argc and argv.

It might be worth a try to set environment variables in your shell and see if they are available to app.GetEnv()

I really don't know whether that will work in your particular environment.

alex.symbroson

unread,
Jul 8, 2018, 5:27:12 PM7/8/18
to DroidScript
DroidScript itself is used for creating android applications - it doesn't make any sense for me to use AndroidDB and DroidScript at the same time - you should decide between them (use DS if you ask me ;)
the reason is that you can simply use a file picker dialog to let the user choose a file and an numeric input field (TextEdit with the "numbers" option) for the resolution value. or probably a spinner box with predefined resolution values.
So using DS may be better in the long run.

If you can't switch to DS any more (because the DroidDB program is too big already) you should probably try to find a real command-line image manipulating tool compiled for android or at least the sources so that you may be able to compile it with an compiler for android (they're cmmonly written in c or c++ - and there are some gcc / g++ compilers for android) - but I think that would take too much time to get this all working but at the end you can use a 'professional' image manipulation program as basis and you don't have to write it yourself. (But also DS has some plugins for image manipulation)

decide which way's the best for you :)

good luck and best regards,
Symbroson

alex.symbroson

unread,
Jul 8, 2018, 5:30:37 PM7/8/18
to DroidScript
with string list I mean the way how layouts get their options for example. "FillXY,Horizontal,TouchThrough"

Frank Vizza

unread,
Jul 8, 2018, 8:47:21 PM7/8/18
to DroidScript
Good information, thank you.
Yes, the droiddb program is already too large to convert. My image annotation needs are minimal and I already have a working system I just wrote in droidscript. For now, I will put my target image into the directory and name it so the photo reduction program can work. The photo may or may not be annotated, depending on user preference, but must be reduced to make a reasonably sized pdf report file.

I am still learning droidscript and struggle with definition of function parameters, I don't think the documentation is complete enough. But I love the product, will stay a premium member for sure and will contemplate converting over in time. I have been running my entire business on visual CE since 2005, covered it to Droiddb and now have a few key programs written in droidscript.

I have 17 different relational databases in my current system with a number of different reports.

So I guess my next droidscript project will include a database. . .

I will also make a suggestion to add reporting capability to droidscript unless it already exists . . .

Dave

unread,
Jul 10, 2018, 6:46:50 AM7/10/18
to DroidScript
You should be able to use am start with intent parameters and catch those parameters in your DS app using the OnData() global callback.



See the DroidScript "Receive Intent" sample for how to get at the parameters.
Reply all
Reply to author
Forward
0 new messages