amclachlan
4/29/2018 - 8:37 PM

Wrapper for sys_process

Wrapper for sys_process

[//lasso
/*----------------------------------------------------------------------------

[Shell_9]
Adaptation of Jason Huck's Shell tag for Lasso 8.5

Author: Jonathan Guthrie
Last Modified: Sep. 29, 2010
License: Public Domain

Description:



Sample Usage:
local(x = shell('cd /path/to/file; chmod 664 helloworld.xml'))

Original version available from http://www.lassosoft.com/tagswap/detail/Shell_9.

2013-05-20	JC	Changed os_process to sys_process, added -> wait
----------------------------------------------------------------------------*/


// ==================================
	/*
		Adapted from Jason Huck's Shell tag from 8.5
	*/
	// ==================================

define shell(cmd::string) => {
	local(os = lasso_version(-lassoplatform))
	local(this = file_forceRoot(response_Path))
	#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)
}
]