How to force Dyalog APL to use a different shell with ⎕sh

The Dyalog "Knowledgebase". This forum is read-only
Forum rules
The FAQ is a read-only forum which is in general updated only by employees of Dyalog Ltd. It replaces the FAQ page which existed under http://www.dyalog.com. Rather than rejecting other posts to this forum, such posts will be put in a moderation queue, and moved to a more appropriate forum.

How to force Dyalog APL to use a different shell with ⎕sh

Postby AndyS|Dyalog on Thu Nov 04, 2010 2:44 pm

Under UNIX, when calling )sh, )cmd, ⎕sh or ⎕cmd Dyalog APL calls the system() library call. The shell which is used to run your command is therefore the shell which system() is defined to call. So for example, under AIX that would be /usr/bin/sh. Under Windows there is no system() call, but Dyalog APL interpreter has a function which preforms a similar action.

You can override this default shell by specifying two environment variables before starting Dyalog APL; CMD_PREFIX and CMD_POSTFIX.

Unix Example: (this is AIX-specific)
To run a restricted shell from within )sh or ⎕sh so that the user could not include "/" in their command

      export CMD_PREFIX="exec Rsh -c \"'$*'"
export CMD_POSTFIX="\""

With this setting, then in an APL session

      ⎕sh'/bin/ls'
Rsh: /bin/ls: 0402-014 The operation is not allowed in a restricted shell.



Windows Example:
To use the PowerShell:
In either the registry or in the shortcut to APL
      CMD_PREFIX="powershell.exe"
CMD_POSTFIX=""


      ⎕cmd'Get-Host'
Name : ConsoleHost
Version : 2.0
InstanceId : 6e334210-e16d-4bc8-a0cb-644291d61cfa
UI : System.Management.Automation.Internal.Host.InternalHostUserI
nterface
CurrentCulture : en-GB
CurrentUICulture : en-US
PrivateData : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
IsRunspacePushed : False
Runspace : System.Management.



Be aware that in all cases you may face issues involving escaping quotes correctly !
User avatar
AndyS|Dyalog
 
Posts: 263
Joined: Tue May 12, 2009 6:06 pm

Re: How to force Dyalog APL to use a different shell with ⎕sh

Postby Geoff|Dyalog on Fri Nov 05, 2010 9:10 am

Some comments on Andy's post: Under Windows the CMD_PREFIX and CMD_POSTFIX can be used to substitute the program actually run by ⎕CMD or )CMD. Thus you can set these up so that an MKS Korn shell is used (why I originally put them in) or so that you can use a Microsoft power shell which hadn't even been thought of. The constructed command is passed to CreateProcess(). I don't think I have seen a description of how CreateProcess() parses its command line.

Standards dictate that it is the Bourne shell shell which is used when calling system - on AIX this is indeed /usr/bin/sh, although if you were to run in a trusted environment, it would be /usr/bin/tsh. Thus the use of CMD_PREFIX and CMD_POSTFIX can only force the replacement of that shell with another after the Bourne shell has been initiated. This is likely to lead to some problems if the command contains quotes.
Geoff|Dyalog
 
Posts: 43
Joined: Wed May 13, 2009 12:36 pm


Return to Frequently Asked Questions (FAQ)

Who is online

Users browsing this forum: No registered users and 1 guest