BookmarkSubscribeRSS Feed
lfabbri
Obsidian | Level 7

Is it possible to start/execute a java program from a jar file in a node of a Data Integration job and wait for completion (exit code 0)?

9 REPLIES 9
Kurt_Bremser
Super User

If XCMD is enabled, you can start external commands, wait for completion, and check for the return code or the output in a user written code node:

x 'java /somepath/prog.jar';

%put &sysrc;

or

filename oscmd pipe 'java /somepath/prog.jar 2>&1';

data _null_;
infile oscmd;
input;
put _infile_;
run;

filename oscmd clear;
lfabbri
Obsidian | Level 7

Hi @Kurt_Bremser, thank you for the answer!

How can I know if XCMD is enabled on my SAS environment?

Kurt_Bremser
Super User

Just try the X statement with something simple, eg

x 'ls';

(ls if you are on UNIX, dir if on Windows).

If XCMD is disabled, you'll get an ERROR message.

But you will need it active if you want to run external commands, so you have to talk with your SAS admin in case its disabled.

lfabbri
Obsidian | Level 7

Hi, I've tried your solutions and they works great in the SAS console. 

 

But when I tried a simple "User Written Code" node in Data Integration Studio with the following code:

 

proc options option=(xcmd xsync JREOPTIONS);
run;

x 'java -version';

I got the following error:

 

ERROR: shell escape is not valid in this SAS session.

 

Do you know why I am getting this error in Data Integration and not in SAS console?

 

Kurt_Bremser
Super User

@lfabbri wrote:

Hi, I've tried your solutions and they works great in the SAS console. 

 

But when I tried a simple "User Written Code" node in Data Integration Studio with the following code:

 

proc options option=(xcmd xsync JREOPTIONS);
run;

x 'java -version';

I got the following error:

 

ERROR: shell escape is not valid in this SAS session.

 

Do you know why I am getting this error in Data Integration and not in SAS console?

 


That's because the workspace server used by DI Studio has XCMD disabled (by default). If you have a need to run external commands, get in touch with your SAS admin to have XCMD enabled.

lfabbri
Obsidian | Level 7

 

I am on a test environment with admin privileges.

 

Following from here http://support.sas.com/kb/41/058.html I've enabled XCMD, but I got the same error when executing that code in DIS.

 

sas_enable_xcmd.png

 

This is the content of the C:\SAS\DIserver\Lev1\SASApp\WorkspaceServer\WorkspaceServer.bat file:

 

@echo off
REM /*--------------------------------------------------------------------\
REM |                                                                     |
REM | Script for managing the SAS Workspace Server                        |
REM |                                                                     |
REM \--------------------------------------------------------------------*/
setlocal

REM Define needed environment variables
call "%~dp0..\appservercontext_env.bat"

Set CONFIGDIR=%APPSERVER_ROOT%\WorkspaceServer
call "%CONFIGDIR%\WorkspaceServer_usermods.bat"
Set CMD_OPTIONS=-config "%CONFIGDIR%\sasv9.cfg" %* %USERMODS_OPTIONS%

"%SAS_COMMAND%" %CMD_OPTIONS%

endlocal

REM Return the appropriate exit code
exit %ERRORLEVEL%

 

This is the content of the C:\SAS\DIserver\Lev1\SASApp\WorkspaceServer\WorkspaceServer_usermods file:

 

REM /*--------------------------------------------------------------------\
REM |                                                                     |
REM | Script to extend WorkspaceServer.bat via user modifications.        |
REM |                                                                     |
REM \--------------------------------------------------------------------*/

Set USERMODS_OPTIONS=

 

 

What can I do?

 

Thank you for the support

lfabbri
Obsidian | Level 7

I've restarted the SAS Servers and now it is working fine. Thank you very much!

Patrick
Opal | Level 21

@lfabbri

This works and I've implemented something not too long ago using DIS calling Tika to extract text from documents.

 

Just implement the call to the JAR file as user written code (or a custom transformation if used more than once). 

You need the following two options set as below:

XCMD

XSYNC

 

To check for these options:

proc options option=(xcmd xsync JREOPTIONS);
run;

To list all options:

proc options;

run; 

 

 

There are multiple ways for calling external programs/OS commands out of SAS. I normally use CALL SYSTEM() or FILENAME PIPE.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 9 replies
  • 2872 views
  • 7 likes
  • 3 in conversation