[Shell_9]

Description

Link: [Shell_9]
Author: Jonathan Guthrie
Category: Technical
Version: 9.x
License: Public Domain
Posted: Sep. 29, 2010
Updated: Sep. 29, 2010
More by this author...

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.

Parameters

none


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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// ==================================
	/*
		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/19/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)
Email:


Password:



Newest

Most Popular

Support tagSwap.net