Skip to content

Instantly share code, notes, and snippets.

@jolle-c jolle-c/shell.lasso
Last active Mar 13, 2019

Embed
What would you like to do?
Wrapper for sys_process
[
/**!----------------------------------------------------------------------------
shell.lasso
Adaptation of Jason Huck's Shell tag for Lasso 8.5
Author: Jonathan Guthrie, Jolle Carlestam
Last Modified: 2018-03-20
License: Public Domain
Sample Usage:
local(x = shell('cd /path/to/file; chmod 664 helloworld.xml'))
2018-03-20 JC Added support to run when not called from web_request
2013-05-20 JC Changed os_process to sys_process, added->wait
----------------------------------------------------------------------------*/
define shell(cmd::string) => {
local(os = lasso_version(-lassoplatform))
if(web_request) => {
local(this = file_forceRoot(response_Path))
else
local(this = io_file_getcwd + '/' + currentCapture->callsite_file->stripLastComponent)
}
#this->replace('//','/')
if(#os >> 'Win') => {
local(shell = sys_process('cmd',(:'/c cd ' + #this + ' && ' + #cmd)))
else(#os >> 'Mac')
local(shell = sys_process('/bin/bash', (:'-c','cd '+#this+'; '+#cmd)))
else
local(shell = sys_process('/bin/sh', (:'-c','cd '+#this+'; '+#cmd)))
}
#shell->wait
local(out = #shell->readString)
!#out->size ? #out = #shell->readerror
#shell->close
return(#out)
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.