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)?
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;
Hi @Kurt_Bremser, thank you for the answer!
How can I know if XCMD is enabled on my SAS environment?
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.
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?
@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.
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.
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
Have you restarted the Object Spawner after making the configuration change in Management Console?
I've restarted the SAS Servers and now it is working fine. Thank you very much!
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.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.