In his blog, Jared details the hoops one must jump through to convince SAS to run system shell commands (such as the X command and SYSTASK) from SAS Enterprise Guide.
Here is the explanation: SAS Enterprise Guide is a client application, and SAS runs as a server application. When launched as a server, SAS disables access to shell commands as a safeguard. You wouldn't want just anyone with access to your server to issue "rm *" or "format c:" commands, now would you? (You're welcome.)
When SAS and Enterprise Guide are running on the same machine, it does seem overprotective to prevent you from issuing shell commands on your own box. You can use Jared's notes to re-enable the X command (using the -ALLOWXCMD option or the older double-negative version: -NONOXCMD).
But what if you could avoid those complicated steps and simply represent your local machine shell script as a step in your SAS Enterprise Guide project? That's exactly what the "System Command" custom task allows you to do.
We provide this task as an example of a custom task that you can use to extend your SAS Enterprise Guide features. In fact, we provide about 20 such examples, with source code, that you can use "as is" or modify as you wish.
What are you waiting for? Download this custom task and take back command.
34 Comments
Hi Chris, I am an Instructor here in Marlow and I am doing some work for a customer who is moving to EG from PC SAS and there is a certain amount of "resistance". One thing that has come up is the X command and this looks like it might be a solution, however before I get too excited, does this work if you have EG on your PC and you are connecting to SAS on a server somewhere. In other words how you would expect to use EG.
Of course the other issue to raise its head is DDE. I have worked out one solution but would be interested in any others you may have. Many thanks in advance!
Simon
Simon, you might also check out:
http://blogs.sas.com/sasdummy/index.php?/archives/136-Using-the-X-and-SYSTASK-commands-from-SAS-Enterprise-Guide.html
And
http://blogs.sas.com/sasdummy/index.php?/archives/113-Accessing-Excel-from-SAS-without-DDE.html
Chris
Hi Chris --
I just discovered this add-in and it works great, thank you for posting this. My only question is this: is it possible to use the system command add-in with a stored process?
Mike, it doesn't translate into a stored process.
But you might check out this topic (if you haven't already) to see how to enable X command and SYSTASK. By default though, the stored process server won't allow shell commands.
http://blogs.sas.com/sasdummy/index.php?/archives/136-Using-the-X-and-SYSTASK-commands-from-SAS-Enterprise-Guide.html
Chris
Thanks Chris. I was hoping to avoid the X command, but I will look into your potential solution. Thanks for the quick response by the way!
Pingback: Using the X and SYSTASK commands from SAS Enterprise Guide - The SAS Dummy
Hi Chris,
Does the filename mkdir pipe ' mkdir path' work in EG.
Thanks in advance
It depends. It does work now in SAS 9.3 for Windows, by default. See this post for details.
For other systems or other SAS versions, you can modify the behavior with options. See this post for details.
Pingback: 11 super-useful custom tasks for SAS Enterprise Guide - The SAS Dummy
Hi Chris,
I've been using this command prompt successfully under EG 5.1 but have just been upgraded to 6.1 and it no longer works? Is there something I am doing wrong?
No errors show up in the log but it isn't doing what it's supposed to. Any ideas?
warm regards
Steve
Steve, the same add-in DLL works in 6.1. Some things to check: is the custom task DLL in the expected location? Did you use Tools->Add-In Manager to register it, or did you drop it into one of the designated "Custom" folders (such as %appdata%\SAS\EnterpriseGuide\6.1\Custom)? The latter approach can be a bit more reliable.
You're a life saver. I was using the Add-In Manager and it was showing up with no problems at all, just not working.
I had to create the Custom folder but it worked straight away.
Thank you very much for your help, much appreciated.
Hi Chris,
Is it possible to declare or pass macro variables to commands in the command prompt task when the local session is disabled? We are going through a SAS platform migration, and we will no longer be able to execute code on a Local session. It will all be done on a UNIX server.
We are looking for alternative solutions within SAS EG to accomplish what we need to keep our processes clean. But a number of our processes copy and delete local files, create and delete folders, etc. We've been struggling to find a SAS solution when we can't use a Local session. We can incorporate non-SAS solutions, but it will create some additional risk for control breaks, hopping between platforms mid-process.
Any help or suggestions you might have are appreciated.
Jeremy, this would be a great enhancement to the command prompt task. I've actually played with adding "macro variable resolution" to this but never got it completed. I can add it to my list. If you don't want to wait for me, the source code for this task is on my GitHub account.
Hi Chris, just want to add my vote for this task supporting macro variables! This would be incredibly useful for us as we create many reports with either the date or client name in the title crated via macros. At the moment I use the task to open up the folder containing these files but would be much better if it opened the actual files.
cheers
Steve
I couldn't get this to work. When I tried to access it from the EG add-in manager, I received this error message: Could not load file or assembly ‘SASCustomExamples’ or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515).
Tim, try the steps described in this blog post to "unblock" the custom task DLL per your local Windows security settings.
The unblocking did work. Thanks. BTW, the bottom link goes to the wrong URL.
Hi Chris
Does "system commands" work with EG 7.1? I unlockded dll but when i try to register the addin the following error
Unable to load file EGAddin4.dll
Error: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
The error above is missing if i load files SASCustomExample.ddl and SASCustomExamplesVB.ddl
warm regards
Alexis
Try this standalone version of the System Commands task, available as an example project with my book. (See the Chapter 14 download. GitHub repository available as well.)
Hi Chris,
I'm trying to use this version with commands containing special characters but there's an encoding problem. For example, the character "é" becomes "é" in the log and the command doesn't successfully run. suggests that it's a case of a string being read with 8-bit encoding. Now I tried my hardest to fix this from your source code by plugging
Encoding.UTF8.GetString(Encoding.Default.GetBytes(cmds));
in a couple of places but my C# only goes so far so I have to admit defeat. Anyway, any ideas for a solution ? ThanksPPaul,
Tricky problem! From what I've read, you actually have to change the console codepage for the process you're launching. Unlike many Windows apps, the console CMD doesn't support Unicode or UTF-8 natively -- you need to go "old school" and actually set an OEM codepage for the encoding you want to run in and retrieve the StdOut. See a similar topic here.
Hi Chris,
Can you please to find system command options in SAS EG 8.3
The System Command task that I originally built and released still works for the latest version of EG. You can find the DLL and source here.
Hi Chris,
First of all, thanks a lot for this task.
We are about to migrate our SAS projects to a SAS Server. So the %SYSEXEC command wont be available,so I think this could be the solution.
I've being playing a bit with the task. I have some projects that copy a file wich name is build out of macro variables so I would need the macrovariable enhancement. To achieve this goal I export the comands to .bat file and then execute this from your task. that was a solution.
But there is two things left...
- How can i know if the command was executed succesfully?. When using %SYSEXEC the macro variable &SYSRC got that information. Is there a way to get this info from your task
- When a command fail the task won't execute the rest of commans even if you separate them with &, || ...
for example, if we set file2.txt as read-only:
copy /Y file1.txt file2.txt || echo WRONG > log.txt
Wont write anything to log.txt (even if i write this to a .bat file and then execute it)
Is there a way to force the execution of all the commands??
Best regards,
Gonzalo
The task -- as it is now -- won't satisfy all of that. The source code for the task is available here -- but it requires a few additional skills and tools to modify and rebuild.
Pingback: SAS Enterprise Guide for SAS programmers - The SAS Dummy
Can you use this utility for SAS University Edition?
Brian, the answer is No. SAS University Edition uses SAS Studio, which runs in your browser and would not be able to run executable commands outside of that environment. And if you're trying to run shell commands within the SAS session (using SYSTASK or FILENAME PIPE), that's not enabled in the SAS University Edition virtual machine (NOXCMD is set, and cannot be changed).
Pingback: Custom tasks for SAS Enterprise Guide: Q&A - The SAS Dummy
Hi Chris, how can I write a command using special caracter like "é" and "í" if my file path there are these caracteres? I tried, but didin't work. cal help me, please?
Ronaldo, some other readers had the same problem (see other comments). The trick is that the Windows CMD console does not support UTF-8 natively, so one must explicitly set the OEM codepage if you're using non-ASCII characters. You can avoid the characters in your script (assuming these are file paths) by specifying the shorter 8.3 versions of the names. You can discover those names for a given path by issuing "dir /X" at a command prompt.
Hi Chris,
first of all thank you for this awesome solution!
I'm using this task to run a python script from the SAS EG process flow. Is there a way to see the output of the script (even if it is outside SAS EG)? I can't see error messages or the outputs I added on the log of the task.
Thanks in advance,
Ricardo Neves
Glad you find it useful! Alas, the task funnels back only the STDOUT from the command, and not any of the other artifacts. There are ways to add such things to custom tasks, but that's more development in the task source code.