cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Mac/Linux trigger Java GUI Scripting from command line

0 Kudos
2,686

Scenario

I am able to trigger a javascript file from command line like this:

test1.js

application.openConnectionByConnectionString("conn=/H/10.10.10.100/S/3200&expert=true");
application.findById("/app/con[0]/ses[0]/wnd[0]/usr/txtRSYST-MANDT").text = "220";
application.findById("/app/con[0]/ses[0]/wnd[0]/usr/txtRSYST-MANDT").setFocus();
application.findById("/app/con[0]/ses[0]/wnd[0]/usr/txtRSYST-MANDT").caretPosition = 3;
application.findById("/app/con[0]/ses[0]/wnd[0]/usr/txtRSYST-BNAME").text = "username";
// The text of a password field is not recorded. Either enter a valid password or delete the following line
application.findById("/app/con[0]/ses[0]/wnd[0]/usr/pwdRSYST-BCODE").text = "secret";
application.findById("/app/con[0]/ses[0]/wnd[0]").resizeWorkingPane(181,35,false);
application.findById("/app/con[0]/ses[0]/wnd[0]").sendVKey(0);
application.findById("/app/con[0]/ses[0]/wnd[0]/tbar[0]/okcd").text = "/nex";
application.findById("/app/con[0]/ses[0]/wnd[0]").sendVKey(0);
#!/bin/bash
export SAPGUIDIR="/Applications/SAP Clients/SAPGUI 7.50rev5/SAPGUI 7.50rev5.app/Contents/Resources"
export WORKDIR=`pwd` # this is where the script file is located

cd "${SAPGUIDIR}"
echo "[DEBUG] starting..."

java \
	-cp Java/GuiStartS.jar com.sap.platin.Gui \
	-n \
	-b \
	-f ${WORKDIR}/test1.js

echo "[DEBUG] done!"

Problem
JavaGUI does not quit. There is a popup that says "The script has successfully completed its execution".

If I run the command again, I get another copy of JavaGUI running ...

How can I get JavaGUI to quit completely?

Please could anyone share a link to the full JavaScript API?

Accepted Solutions (1)

Accepted Solutions (1)

robert_straub
Product and Topic Expert
Product and Topic Expert
0 Kudos

On macOS just add parameters "-t NOPHANTOM" in the script, then the JavaGUI will exit when the connection is closed.

And instead of calling "java ... -jar GuiStartS.jar..." you can call

"/Applications/SAP Clients/SAPGUI 7.50rev5/SAPGUI 7.50rev5.app/Contents/MacOS/SAPGUI -n -b ...."

This will start the JavaGUI with the appropriate java version.

Regards

Robert

SAP GUI for Java

0 Kudos

Sweet, thanks for sharing!

Do you have any link / PDF on the flags for SAPGUI?

0 Kudos

Great - the GUI does not remain active after the script.

"${SAPGUIDIR}/MacOS/SAPGUI" \
    -n \
    -b \
    -t NOPHANTOM \
    -f ${WORKDIR}/test1.js

But it's messy... note this line in the output : TRC and AUTDMP were not requested?

31.01. 17:01:49.270 TRC: Active trace keys: NOPHANTOM:TRC:AUTDMP
2020-01-31 17:01:48.845 SAPGUI[78711:3683840] Task succeeded.
31.01. 17:01:49.269 TRC: -----------------------------------------------------------
31.01. 17:01:49.269 TRC: Date: 31.01. 17:01:49.257
31.01. 17:01:49.269 TRC: -----------------------------------------------------------
31.01. 17:01:49.269 TRC: System Details
31.01. 17:01:49.269 TRC: -----------------------------------------------------------
31.01. 17:01:49.269 TRC: Java VM: Oracle Corporation Version 10.0.2+13
31.01. 17:01:49.269 TRC: Bit Mode: 64
31.01. 17:01:49.269 TRC: OS: Mac OS X(x86_64) Version 10.15.3
31.01. 17:01:49.269 TRC: Java Directory: /Library/Java/JavaVirtualMachines/jdk-10.0.2.jdk/Contents/Home
31.01. 17:01:49.269 TRC: Home Directory: /Users/derek
31.01. 17:01:49.269 TRC: Current Directory: /Applications/SAP Clients/SAPGUI 7.50rev5
31.01. 17:01:49.269 TRC: Locale: English (United Kingdom)
31.01. 17:01:49.269 TRC: Default Character Encoding: UTF8
31.01. 17:01:49.269 TRC: -----------------------------------------------------------
31.01. 17:01:49.269 TRC: Product Details
31.01. 17:01:49.269 TRC: -----------------------------------------------------------
31.01. 17:01:49.269 TRC: SAP GUI for Java 7.50 rev 5
31.01. 17:01:49.269 TRC: 2018-12-05 06:30:12 +0100
31.01. 17:01:49.269 TRC: mo-f75228bd7, 750_REL, 1889363
31.01. 17:01:49.269 TRC: (Version ID A075000040500)
31.01. 17:01:49.270 TRC: Active trace keys: NOPHANTOM:TRC:AUTDMP <<====================== WHY???
31.01. 17:01:50.572 TRC: Installation Details
31.01. 17:01:50.572 TRC: -----------------------------------------------------------
31.01. 17:01:50.572 TRC: Private Glob File: /Users/derek/Library/Preferences/SAP/globs
31.01. 17:01:50.572 TRC: Desktop integration: Mac OS X integration (library: /Applications/SAP Clients/SAPGUI 7.50rev5/SAPGUI 7.50rev5.app/Contents/Resources/bin/libMacOSXConnect64.dylib exists: true)
31.01. 17:01:50.572 TRC: -----------------------------------------------------------
31.01. 17:01:50.572 TRC: Path Information:
31.01. 17:01:50.572 TRC: -----------------------------------------------------------
31.01. 17:01:50.572 TRC: SAP GUI traces          : </Users/derek/Library/Preferences/SAP/traces>
31.01. 17:01:50.572 TRC: SAP GUI user prefs      : </Users/derek/Library/Preferences/SAP>
31.01. 17:01:50.572 TRC: SAP GUI system prefs    : </Library/Preferences/SAP>
31.01. 17:01:50.572 TRC:  
31.01. 17:01:50.572 TRC: Installation Dir        : </Applications/SAP Clients>
31.01. 17:01:50.572 TRC: Product Dir             : </Applications/SAP Clients/SAPGUI 7.50rev5>
31.01. 17:01:50.572 TRC: Application Dir         : </Applications/SAP Clients/SAPGUI 7.50rev5/SAPGUI 7.50rev5.app>
31.01. 17:01:50.572 TRC: Resource Dir            : </Applications/SAP Clients/SAPGUI 7.50rev5/SAPGUI 7.50rev5.app/Contents/Resources>
31.01. 17:01:50.572 TRC:  
31.01. 17:01:50.572 TRC: Binary Dir              : </Applications/SAP Clients/SAPGUI 7.50rev5/SAPGUI 7.50rev5.app/Contents/Resources/bin>
31.01. 17:01:50.572 TRC: GMUX Dir                : </Applications/SAP Clients/SAPGUI 7.50rev5/SAPGUI 7.50rev5.app/Contents/Resources/bin/gmux>
31.01. 17:01:50.572 TRC: Jar Dir                 : </Applications/SAP Clients/SAPGUI 7.50rev5/SAPGUI 7.50rev5.app/Contents/Resources/Java>
31.01. 17:01:50.572 TRC: Install Script Dir      : </Applications/SAP Clients/SAPGUI 7.50rev5/SAPGUI 7.50rev5.app/Contents/Resources/inst>
31.01. 17:01:50.572 TRC: Security Dir            : </Applications/SAP Clients/SAPGUI 7.50rev5/SAPGUI 7.50rev5.app/Contents/Resources/security>
31.01. 17:01:50.572 TRC: Documentation Dir       : </Applications/SAP Clients/SAPGUI 7.50rev5/SAPGUI 7.50rev5.app/Contents/Resources/doc>
31.01. 17:01:50.572 TRC:  
31.01. 17:01:50.572 TRC: Default Installation Dir: </Users/derek/Applications/SAP Clients>
31.01. 17:01:50.572 TRC: System Installation Dir : </Applications/SAP Clients>
31.01. 17:01:50.572 TRC: User Installation Dir   : </Users/derek/Applications/SAP Clients>
31.01. 17:01:50.572 TRC:  
31.01. 17:01:50.572 TRC: Files:
31.01. 17:01:50.572 TRC: Installation Script     : </Applications/SAP Clients/SAPGUI 7.50rev5/SAPGUI 7.50rev5.app/Contents/Resources/inst/install>
31.01. 17:01:50.572 TRC: Deinstaller             : <null>
31.01. 17:01:50.572 TRC: guilogon                : </Applications/SAP Clients/SAPGUI 7.50rev5/SAPGUI 7.50rev5.app/Contents/Resources/bin/guilogon>
31.01. 17:01:50.572 TRC: guistart                : </Applications/SAP Clients/SAPGUI 7.50rev5/SAPGUI 7.50rev5.app/Contents/Resources/bin/guistart>
31.01. 17:01:50.572 TRC: Installation LOCK       : </Applications/SAP Clients/SAPGUI 7.50rev5/platin.lock>
31.01. 17:01:50.572 TRC: Installation Log        : </Users/derek/Library/Logs/sapgui.log>
31.01. 17:01:50.572 TRC: Permissions             : </Applications/SAP Clients/SAPGUI 7.50rev5/SAPGUI 7.50rev5.app/Contents/Resources/permissions>
31.01. 17:01:50.572 TRC: -----------------------------------------------------------
31.01. 17:01:50.572 TRC: List of active code sources
31.01. 17:01:50.572 TRC: -----------------------------------------------------------
31.01. 17:01:50.572 TRC: Classloader:com.sap.platin.micro.MicroURLClassLoader@1b2abca6

.... big snip ....

31.01. 17:01:50.572 TRC: -----------------------------------------------------------
31.01. 17:01:50.572 TRC: The jar folder contains the following jar files:
31.01. 17:01:50.572 TRC: -----------------------------------------------------------
31.01. 17:01:50.572 TRC: sapTextEditS.jar
31.01. 17:01:50.572 TRC: sapInputFieldS.jar
31.01. 17:01:50.572 TRC: sapJnetS.jar
31.01. 17:01:50.572 TRC: sapContextMenuS.jar
31.01. 17:01:50.572 TRC: JNetBeanS.jar
31.01. 17:01:50.572 TRC: plafbaseS.jar
31.01. 17:01:50.572 TRC: iCubeS.jar
31.01. 17:01:50.572 TRC: platincore9S.jar
31.01. 17:01:50.572 TRC: sapImageS.jar
31.01. 17:01:50.572 TRC: pdfViewerS.jar
31.01. 17:01:50.572 TRC: sapToolBarS.jar
31.01. 17:01:50.572 TRC: sapCalendarS.jar
31.01. 17:01:50.572 TRC: sapComboBoxS.jar
31.01. 17:01:50.572 TRC: sapPdfViewerS.jar
31.01. 17:01:50.572 TRC: platinsecS.jar
31.01. 17:01:50.572 TRC: sapHtmlCoreS.jar
31.01. 17:01:50.572 TRC: sapTreeS.jar
31.01. 17:01:50.572 TRC: sapChartS.jar
31.01. 17:01:50.572 TRC: sapHtmlS.jar
31.01. 17:01:50.572 TRC: GuiStartS.jar
31.01. 17:01:50.572 TRC: platinlangS.jar
31.01. 17:01:50.572 TRC: platinr3S.jar
31.01. 17:01:50.572 TRC: platinwdpS.jar
31.01. 17:01:50.572 TRC: platinMacOSXS.jar
31.01. 17:01:50.572 TRC: sapGridS.jar
31.01. 17:01:50.572 TRC: platincoreS.jar

Answers (4)

Answers (4)

raniemi
Newcomer
0 Kudos

In case someone comes across this thread and that they're having issues with SAPGUI for Java 7.80:

  • The NOPHANTOM trace appears to be replaced with SCRIPTNOMESSAGE
    • The reason why this works is because setting this trace (as a side effect) puts SAPGUI into "unattended mode"
  • If you rather not use SCRIPTNOMESSAGE (and see unnecessary tracing) then at the beginning of your script you can do the following (undocumented) trick:
    • application.unwrap(application).mUnattended = true;
  • I know there are references in this thread about how the SAPGUI can/will exit after the script completes and elsewhere in the SAPGUI documentation it suggests that closing connections/sessions should shutdown the SAPGUI -- but this has not been my experience. 
    • After closing the connections/sessions and confirming it completed with the SHUTDOWN trace, at the end of my script I now call:
      • java.lang.System.exit(0);
    • NOTE: This will not work with the Java Security policy that is shipped with the SAPGUI.  I had to call the SAPGUI using Java (like the author originally did) and pass in the absolute path for a custom security policy to the JVM at start up:
      • java -Djava.security.policy=file://...
    • The contents of the security policy I used are:
      • grant principal com.sap.platin.micro.GuiPrincipal "SAPGUI:UserScript" {
            permission java.io.FilePermission "<<ALL FILES>>", "read,write,delete,execute";
            permission java.lang.RuntimePermission "getenv.*";
            // Generic Permissions necessary for Scripting
            permission javax.security.auth.AuthPermission "doAsPrivileged";
            permission java.awt.AWTPermission "createRobot";
         
            // Allow the script to exit
            permission java.lang.RuntimePermission "exitVM";
        };
RMW
Product and Topic Expert
Product and Topic Expert
0 Kudos

The public trace keys are listed in chapter "5.3.3 Trace Information" of the manual available via Help > SAP GUI Help. They usually are intended to switch on tracing in particular components for debugging purposes.

There are a few more to modify the behavior, but they are not published by intention.

RMW
Product and Topic Expert
Product and Topic Expert
0 Kudos

Using parameter -? will print the list of parameters.

0 Kudos

LOL, reverse-engineering the documentation...

...there is no mention of "NOPHANTOM" - not even the mighty Google has any record of this feature

"/Applications/SAP Clients/SAPGUI 7.50rev5/SAPGUI 7.50rev5.app/Contents/MacOS/SAPGUI" -h
2020-01-31 16:34:14.902 SAPGUI[77876:3663785] Task succeeded.
############################# ERROR #############################
31.01. 16:34:16.926 ERROR: Getopt.nextOption(): Unrecognized option: -h
############################# ERROR #############################
com.sap.platin.base.logon.GuiImpl: start program for PlatinGui
Usage: com.sap.platin.base.logon.GuiImpl [options]
Available options:
/Rfc=[0-9A-F][0-9A-F]* RFC id to send to backend during connect
-o <hostSpec>opens a connection to <hostSpec> (e.g. /H/binmain/S/3253)
-f <fileName>executes the script contained in the file <fileName>
-s <script>executes the script contained in string <script<
-w opens a script window for manual script input
-n doesn't show guilogon window
-t <traceKeys> activates all trace keys contained in string <traceKeys>
(delimited by commas, e.g. CON,SES,EVT,C_AGI)
-l <traceFile> writes trace information activated by trace keys with the option -t
into the log file <traceFile>
-p <libdir>path to the JPlatin library
-g <gmuxpath>path to Gmux
-b no progress bar
-? prints this help text
The options '-f' and '-s' may occur repeatedly and in any order (they are evaluated in the order
they appear).
RMW
Product and Topic Expert
Product and Topic Expert
0 Kudos
0 Kudos

Thanks Rolf - that link does not cover JS in the detail I need.