- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
create?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Before you try to make your code dynamic, get it to run with literal values.
Maxim 34: Work in Steps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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";
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Still doesn't work. I attached the log in the post, thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You get a Java exception; that has to be fixed on the Java side.
The SAS part works.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.