Lasso Soft Inc. > Home

[Shell_9]

LinkShell_9
AuthorJonathan Guthrie
CategoryTechnical
Version9.x
LicensePublic Domain
Posted29 Sep 2010
Updated29 Sep 2010
More by this author...

Description

This is a simple wrapper for the [os_process] type that allows you to interact with a bash shell, similar to how you would if you were using Terminal on OS X. On Windows, it interacts with the cmd process. The tag creates a new [os_process] type, opens a new shell, and executes whatever command is passed to it.

Sample Usage

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

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.

	// ==================================
	/*
		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 = os_process('cmd',(:'/c cd ' + #this + ' && ' + #cmd)))         
        else(#os >> 'Mac') 
            local(shell = os_process('/bin/bash', (:'-c','cd '+#this+'; '+#cmd)))
        else
            local(shell = os_process('/bin/sh', (:'cd '+#this+'; '+#cmd)))
		}
        local(out = #shell->readString) 
        !#out->size ? #out = #shell->readerror 
        #shell->close
        return(#out) 
	}

Related Tags

Comments

07 Jun 2012, Brad Lindsay

This uses sys_process & lets you specify the user to run as

// Assumes /bin/bash (not Windows friendly)
define shell(cmd::string, user::string='') => {
local(process) = sys_process
local(stdout, stderr)

#user == '' ?
#process->open('/bin/bash', (:'-c', #cmd))
| #process->open('/bin/bash', (:'-c', #cmd), (:), #user)
#process->wait
#stdout = #process->read
#stderr = #process->readError
#process->close

return (:#stdout, #stderr)
}

19 Jul 2011, Jolle Carlestam

Bug in Centos section

There's an omission that cause the method to fail on Centos.
Change this:
local(shell = os_process('/bin/sh', (:'cd '+#this+'; '+#cmd)))
to
local(shell = os_process('/bin/sh', (:'-c','cd '+#this+'; '+#cmd)))
(As of 2011-07-19)

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft