Architecting, installing and maintaining your SAS environment

sas-recover-metadata executed via call system() out of SAS EG

Accepted Solution Solved
Reply
Respected Advisor
Posts: 4,173
Accepted Solution

sas-recover-metadata executed via call system() out of SAS EG

Hi all,

 

http://support.sas.com/documentation/cdl/en/bisag/68240/HTML/default/viewer.htm#p0m27cjip6kjkvn1lhz7...

 

I'm excuting the following code out of a SAS EG session (Win7, SAS 9.4, EG 7.13 HF3).

 

options noxwait xsync;
data _null_;
  length cmd $2000;
  cmd='"C:\Program Files\SASHome\SASPlatformObjectFramework\9.4\tools\admin\sas-recover-metadata.exe"';
  cmd=catx(' ',cmd,"-host %sysfunc(getoption(metaserver))");
  cmd=catx(' ',cmd,"-port %sysfunc(getoption(metaport))");
  cmd=catx(' ',cmd,"-user %sysfunc(getoption(metauser))"); 
  cmd=catx(' ',cmd,"-password &metapw_tmp"); 
  cmd=catx(' ',cmd,"-time 2017-03-16T18:22:27"); 
  cmd=catx(' ',cmd,"-rollForward"); 
  cmd=catx(' ',cmd,"-list");
/*  cmd=catx(' ',cmd,'>>c:\temp\list.txt');*/
  call system(cmd);
  stop;
run;

 

This works as expected and I'm seeing the following in a DOS prompt:

Capture.PNG

 

I've got two challenges where I just can't find a solution.

 

1. Capture message

I would like to capture the returned message from sas-recover_metadata.exe - just what I get in the DOS prompt in above screen shot.

When running the command directly out of a DOS prompt I simply add >>c:\temp\list.txt. That works just fine. BUT when I'm adding this bit to my call system() command as done in above code (the bit in comment) then things fall over and I end up with the following:

Capture.PNG

What am I missing??

 

2. Suppress DOS window

When using call system() is there any way how I could suppress the DOS prompt to show up? Something similar to -nosplash?

 

What I actually want: Just run sas-recover_metadata.exe and write any return messages back to the SAS log. I understand that this runs as a child process so I was thinking to just write everything to a temporary file and then write the content of this file back to the SAS log (via a data _null_ step).

 

Any guidance, pointers or working code would be highly appreciated.

What's a given: Execution out of SAS EG and/or a Stored Process.

 

 

 


Accepted Solutions
Solution
‎03-16-2017 08:59 AM
Trusted Advisor
Posts: 1,314

Re: sas-recover-metadata executed via call system() out of SAS EG

[ Edited ]

Hello @Patrick,

 

nice question! Smiley Happy

 

Let me please answer your direct questions, then I will add some considerations:

 

  1. Capture the message:
    1. first I would try by adding some spaces between the ">>" sign> Somehow it looks as the command is recognizing the output pipe as a parameter.
    2. Secondly, in order to capture the output of system commands, SAS generally recoments to use the FILENAME - PIPE combo: http://blogs.sas.com/content/sgf/2016/03/11/using-a-pipe-to-return-the-output-of-an-operating-system...
  2. Supress DOS window:
    1. the system command "START /MIN /B your_program >> your_output.log" is your friend, and the closest to the Linux command "your_program &". You can use Powershell (start -NoNewWindow your_program ), as well as other tricks that can be googled.

 

My main consideration here would be:

  • Try to prevent as much as possible to pass paswords as normal macro variables, specially if it is the sasadm@saspw user's and through a EG session. Sorry, I had to say it Smiley Happy
  • I would just create a bat file on the server itself, with all your command, with the parameter of the datetime only, for the "-time" option. Then you can make a simple call to
    cmd="your_bat_file &your_datetime";
    call system(cmd);
    Way simplier for you and, linked to my previous comment, more secure.
  • STP would be better than EG (since you can make available this to relevant locations and with a prompt), but, still, a batch process with no log to EG, except the exit of the command, would be even better

 

View solution in original post


All Replies
Solution
‎03-16-2017 08:59 AM
Trusted Advisor
Posts: 1,314

Re: sas-recover-metadata executed via call system() out of SAS EG

[ Edited ]

Hello @Patrick,

 

nice question! Smiley Happy

 

Let me please answer your direct questions, then I will add some considerations:

 

  1. Capture the message:
    1. first I would try by adding some spaces between the ">>" sign> Somehow it looks as the command is recognizing the output pipe as a parameter.
    2. Secondly, in order to capture the output of system commands, SAS generally recoments to use the FILENAME - PIPE combo: http://blogs.sas.com/content/sgf/2016/03/11/using-a-pipe-to-return-the-output-of-an-operating-system...
  2. Supress DOS window:
    1. the system command "START /MIN /B your_program >> your_output.log" is your friend, and the closest to the Linux command "your_program &". You can use Powershell (start -NoNewWindow your_program ), as well as other tricks that can be googled.

 

My main consideration here would be:

  • Try to prevent as much as possible to pass paswords as normal macro variables, specially if it is the sasadm@saspw user's and through a EG session. Sorry, I had to say it Smiley Happy
  • I would just create a bat file on the server itself, with all your command, with the parameter of the datetime only, for the "-time" option. Then you can make a simple call to
    cmd="your_bat_file &your_datetime";
    call system(cmd);
    Way simplier for you and, linked to my previous comment, more secure.
  • STP would be better than EG (since you can make available this to relevant locations and with a prompt), but, still, a batch process with no log to EG, except the exit of the command, would be even better

 

Respected Advisor
Posts: 4,173

Re: sas-recover-metadata executed via call system() out of SAS EG

Posted in reply to JuanS_OCS

Hi @JuanS_OCS

 

Firstly thanks a lot for your fast and detailed answer. That was very helpful :-);

 

The Pipe did the trick for me - quoting was a b... though.

%metaEnvInit(metapw=y);

options noxwait xsync;
data _null_;
  length cmd $2000;
  cmd="""""&adminTools\sas-recover-metadata.exe""""";
  cmd=catx(' ',cmd,"-host %sysfunc(getoption(metaserver))");
  cmd=catx(' ',cmd,"-port %sysfunc(getoption(metaport))");
  cmd=catx(' ',cmd,"-user %sysfunc(getoption(metauser))"); 
  cmd=catx(' ',cmd,"-password &metapw_tmp"); 
  cmd=catx(' ',cmd,"-time %sysfunc(datetime(),e8601dt19.)"); 
  cmd=catx(' ',cmd,"-rollForward"); 
/*  cmd=catx(' ',cmd,"-list");*/
/*  put cmd;*/
  call symputx('cmd',cmd);
  stop;
run;
%symdel metapw_tmp;

filename test pipe "&cmd";
data _null_;
  file print;
  infile test;
  input;
  put _infile_;
run;

I agree with everything you write. What I'm doing is in the moment only for a demo so it doesn't need to be production worthy. 

 

My first choice would be SMC but if EG or a Web Interface is a must then I believe I'd go for a stored process which uses a secure compiled macro where I'd have full control what gets written to the log - or even better I can use the -profile option and don't need to pass in credentials at all. But that's still in the future and I don't even have the requirements yet to make such design decisions.

 

Thanks again for your support. That really helped.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 197 views
  • 3 likes
  • 2 in conversation