Last active
March 13, 2019 06:07
-
-
Save jolle-c/7e3a6a0d30a032573bb67eae423ff865 to your computer and use it in GitHub Desktop.
Wrapper for sys_process
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
/**!---------------------------------------------------------------------------- | |
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