- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
One of our stored processes is using unnamed PIPE to run an exe file to parse addresses. Whenever it fails it logs a stderr output similar to the one below in the log and the process continues. We can not find out it failed until we look at the output or the log.
How can we get our process to abort as soon as it finds stderr output from PIPE command ?
filename adv pipe "&cmd &inputFile. &location";
Stderr output:
Unhandled Exception: System.ServiceModel.FaultException`1[System.ServiceModel.ExceptionDetail]: Error 96: ERR_STAN_DLL_CALL_EXCEPTION. iPaf32.dll:FixLastLine
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Kurt, this works using redirection of stderr to stdout and conditional processing.
filename adv pipe "&cmd &inputFile. &location 2>&1";
data _null_;
infile adv truncover;
input;
if index(lowcase(_infile_),'exception:') then do;
error ' Process Failed with an Exception';
abort;
end;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Add a short command:
filename adv pipe "&cmd &inputFile. &location; echo $?";
The last line in your input will now contain the return code from your command.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Here my input is a text file and the pipe command creates an output file with same name as input but with different extension.
I did not get the return code anywhere after adding echo.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Mind that my shell code is for UNIX. If you are running SAS on Windows (yucc), you will have to use Windows syntax, but the principle should be the same. What I think will also work in Windows is 2>&1 (redirection of stderr to stdout).
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Kurt, this works using redirection of stderr to stdout and conditional processing.
filename adv pipe "&cmd &inputFile. &location 2>&1";
data _null_;
infile adv truncover;
input;
if index(lowcase(_infile_),'exception:') then do;
error ' Process Failed with an Exception';
abort;
end;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Does that mean I need to look for the return code in my input text file ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
When used in an infile statement, the file reference created from filename pipe sends all output from the external command(s) to the input statement(s) in the data step. Since the final command displays the return code from the immediately preceding command, this will be the last "line" of your input.
Still keep in mind that
echo $?
is UNIX syntax. Windows should work with
echo %errorlevel%