BookmarkSubscribeRSS Feed
ZHOUD
Calcite | Level 5

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.

10 REPLIES 10
Kurt_Bremser
Super User

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.

ZHOUD
Calcite | Level 5
Yes, there is additional logic in java software need to be ran. Not sure if
I can see the java code because it's an external software. I did see your
other posts suggesting filename pipe code for jar file, but couldn't figure
it out. Thanks.
Kurt_Bremser
Super User

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.

ZHOUD
Calcite | Level 5
which part of the code can tell the java software to use the txt file I
create?
ZHOUD
Calcite | Level 5

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"; 

 

 

Kurt_Bremser
Super User

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.

ZHOUD
Calcite | Level 5

Still doesn't work. I attached the log in the post, thanks. 

ZHOUD
Calcite | Level 5

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.

 

 

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 10 replies
  • 1266 views
  • 0 likes
  • 2 in conversation