A Java Bean to start external programmes and get both standard and error output
By francois degrelle on Friday, March 27 2015, 15:07 - PJC - Javabean - Permalink
Purpose
Here is a Java bean that allows to start programmes on the client machine, then capture the standard/error output.
It could be used if you don't want to install or use the Webutil library.
If you target to use parameters that contain blanks, separate them by a comma.
The output lines are sent by the external programme (and received by Forms) asynchronously.
The Java code
JavaHost.java
The implementation class of the Bean Item
oracle.forms.fd.JavaHost
The methods you can call
- Set the command
Set_Custom_Property( 'BL.BEAN', 1, 'SET_PROG', 'command' ) ;
e.g. :
Set_Custom_Property('BL.BEAN', 1, 'SET_PROG', 'cmd /c dir /b d:/*.jpg' ) ;
If you intend to use parameters that contains blanks, use a comma to seperate them:
Set_Custom_Property('BL.BEAN', 1, 'SET_PROG', 'cmd,/c,findstr,"width height", d:/oracle9i/forms90/server/formsweb.cfg' ) ;
The event raised by the bean
- MSGSTND
This event is raised by the bean to inform Forms that a line has been sent by the external process on the standard output.
- MSGERROR
This event is raised by the bean to inform Forms that a line has been sent by the external process on the error output.
Here is the code of the When-Custom-Item-Event trigger of the sample dialog:
DECLARE
eventName varchar2(30) := :system.custom_item_event;
eventValues ParamList;
eventValueType number;
LC$Msg Varchar2(32000);
LC$Item varchar2(256);
LC$Event varchar2(256);
BEGIN
IF (eventName='MSGSTND') THEN
-- get the standard output --
eventValues := get_parameter_list(:system.custom_item_event_parameters);
get_parameter_attr(eventValues,'MSGTEXT',eventValueType, LC$Msg);
If Length(:BL.RESULT) + Length(LC$Msg) > 32000 Then
:BL.RESULT := '' ;
End if ;
:BL.RESULT := :BL.RESULT || LC$Msg || CHR(10) ;
Synchronize;
ELSIF (eventName='MSGERROR') THEN
-- get the component properties --
eventValues := get_parameter_list(:system.custom_item_event_parameters);
get_parameter_attr(eventValues,'MSGTEXT',eventValueType, LC$Msg);
If Length(:BL.RESULT) + Length(LC$Msg) > 32000 Then
:BL.RESULT := '' ;
End if ;
:BL.RESULT := :BL.RESULT || ' *** ERROR ***' || CHR(10) || LC$Msg || CHR(10) ;
Synchronize;
END IF;
END;
The sample dialog
. Download the javahost.zip file
. Unzip the file
. copy the javahost.jar file in the <ORACLE_HOME>/forms/java directory
. Edit your /forms/server/formsweb.cfg file to add this jar file
. Open the JAVA_HOST.fmb module (Oracle Forms 9.0.2)
. Compile all and run the module
The .jar file must be signed
The javahost.jar file provided with the .zip file is already signed