B4J Question jShell - passing variables

atiaust

Active Member
Licensed User
Longtime User
Hi All

I am using jShell to start another B4J app on a remote server which works fine.

My question is how do I pass a variable to the remote app so that it is accessible from the
Appstart(from1 as Form, Args() as String).

I start the remote app with
B4X:
Sub startApp
    Log("Starting Remote App")
    jshl.Initialize("jsl","java",Array As String("-jar","myApp.jar"))
    jshl.WorkingDirectory = "Z:\B4jApps"
    jshl.run(-1)
End Sub

I tried adding the string after "myApp.jar" but I am pretty sure that isn't correct.

Any one know?

Thanks
 

jmon

Well-Known Member
Licensed User
Longtime User
in cmd, try typing "java -help" you will get all the parameters:
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:\Users\bbb>java -help
Usage: java [options] class [args...]
(to execute a class)
or java [options] -jar jarfile [args...]
(to execute a jar file)
or java [options] -p <modulepath> -m <modulename>[/<mainclass>] [args...]
(to execute the main class in a module)

where options include:

-d32 Deprecated, will be removed in a future release
-d64 Deprecated, will be removed in a future release
-client is a synonym for the "server" VM [deprecated]
-cp <class search path of directories and zip/jar files>
-classpath <class search path of directories and zip/jar files>
--class-path <class search path of directories and zip/jar files>
A ; separated list of directories, JAR archives,
and ZIP archives to search for class files.
-p <module path>
--module-path <module path>...
A ; separated list of directories, each directory
is a directory of modules.
--upgrade-module-path <module path>...
A ; separated list of directories, each directory
is a directory of modules that replace upgradeable
modules in the runtime image
-m <module>[/<mainclass>]
--module <modulename>[/<mainclass>]
the initial module to resolve, and the name of the main class
to execute if not specified by the module
--add-modules <modulename>[,<modulename>...]
root modules to resolve in addition to the initial module.
<modulename> can also be ALL-DEFAULT, ALL-SYSTEM,
ALL-MODULE-PATH.
--limit-modules <modulename>[,<modulename>...]
limit the universe of observable modules
--list-modules [<modulename>[,<modulename>...]]
list the observable modules and exit
--dry-run create VM but do not execute main method.
This --dry-run option may be useful for validating the
command-line options such as the module system configuration.
-D<name>=<value>
set a system property
-verbose:[class|gc|jni]
enable verbose output
-version print product version to the error stream and exit
--version print product version to the output stream and exit
-showversion print product version to the error stream and continue
--show-version
print product version to the output stream and continue
-? -h -help
print this help message to the error stream
--help print this help message to the output stream
-X print help on extra options to the error stream
--help-extra print help on extra options to the output stream
-ea[:<packagename>...|:<classname>]
-enableassertions[:<packagename>...|:<classname>]
enable assertions with specified granularity
-da[:<packagename>...|:<classname>]
-disableassertions[:<packagename>...|:<classname>]
disable assertions with specified granularity
-esa | -enablesystemassertions
enable system assertions
-dsa | -disablesystemassertions
disable system assertions
-agentlib:<libname>[=<options>]
load native agent library <libname>, e.g. -agentlib:jdwp
see also -agentlib:jdwp=help
-agentpath:<pathname>[=<options>]
load native agent library by full pathname
-javaagent:<jarpath>[=<options>]
load Java programming language agent, see java.lang.instrument

-splash:<imagepath>
show splash screen with specified image
HiDPI scaled images are automatically supported and used
if available. The unscaled image filename, e.g. image.ext,
should always be passed as the argument to the -splash option.

The most appropriate scaled image provided will be picked up
automatically.
See the SplashScreen API documentation for more information.
@<filepath> read options from the specified file

To specify an argument for a long option, you can use --<name>=<value> or
--<name> <value>.

--> java [options] -jar jarfile [args...]
so it seems that you should pass it this way, by just adding your args after the jarfile filename:
B4X:
Sub startApp
    Log("Starting Remote App")
    jshl.Initialize("jsl","java",Array As String("-jar","myApp.jar", "arg1", "arg2", "arg3"))
    jshl.WorkingDirectory = "Z:\B4jApps"
    jshl.run(-1)
End Sub
 
Upvote 0

atiaust

Active Member
Licensed User
Longtime User
Thanks jmon,

Tried that. I added 'arg1' as a string " = OK"

In the app the called app , I checked for a string of any length ie

B4X:
Sub appstart(form1 as form, arg() as string)
      If arg(0).length > 0 then
          Log("found arg(0)")
     end if

Nothing shows up in the logs..
 
Upvote 0

jmon

Well-Known Member
Licensed User
Longtime User
it works for me ??
try this:
B4X:
For i = 0 To Args.Length -1
    Log(Args(i))
Next
that will loops through all your args and log them.

I'm not sure, but it could be because of the spaces. in this case try "shl.InitializeDoNotHandleQuotes", and add quotes around your args:
B4X:
Sub startAppLog("Starting Remote App")
    jshl.InitializeDoNotHandleQuotes("jsl","java",Array As String("-jar","myApp.jar", $"" = OK""$))
    jshl.WorkingDirectory = "Z:\B4jApps"
    jshl.run(-1)
End Sub
notice how the args are wrapped into double quotes: $"" = OK""$
 
Upvote 0

atiaust

Active Member
Licensed User
Longtime User
Thanks jmon,

Sorry there was a typo in my last post. Should have been 'arg1' as a string = "OK" ....(fat fingers)

Will try your suggestion
 
Upvote 0

Similar Threads

Top