Hi, I have an external jar software which uses txt file as input and exports csv file. Previously I type command in command prompt to run the software but I want to automate this step in SAS. I generate txt input file in SAS and want to write sas code to trigger java software to take the input file and generate output. Can anyone help me with this step? Thanks.
You can easily create csv files with SAS, and if there's additional logic in the Java code, pull it into SAS to get a more homogenous environment.
Running software without knowing what it really does can come back to bite you in the behind.
Running an external command with filename pipe goes like this:
Get the command running from the command line, in the same context that your SAS session runs in.
Once that is done, create the following code:
filename oscmd pipe "command as you ran it 2>&1";
data _null_;
infile oscmd;
input;
put _infile_;
run;
the 2>&1 redirects error messages to the pipe, so you can see everything in the SAS log.
Please post your log here if you still have problems.
Before you try to make your code dynamic, get it to run with literal values.
Maxim 34: Work in Steps.
Not sure if i fully understand the process.
Here is the command I put in the command prompt: java -jar abc.jar -i C:\Users\test_input.txt
so i just put the same command in SAS like this?
filename oscmd pipe "C:\Users\abc.jar, java -jar abc.jar -i C:\Users\test_input.txt 2>&1";
So this is your command:
java -jar abc.jar -i C:\Users\test_input.txt
?
Then your SAS code needs to be
filename oscmd pipe "java -jar abc.jar -i C:\Users\test_input.txt 2>&1";
data _null_;
infile in;
input;
put _infile_;
run;
Post the log if it does not work as you intended.
Still doesn't work. I attached the log in the post, thanks.
You get a Java exception; that has to be fixed on the Java side.
The SAS part works.
I figured it out. I missed your "in the same context that your SAS session runs in". I modified my code to
filename oscmd pipe 'cd redirect-path && java -jar "C:\Users\abc.jar" -i "C:\Users\test_input.txt" 2>&1';
and it works. Thanks for your help.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.