[shell]

Description

Link: [shell]
Author: Jason Huck
Category: OS Process
Version: 8.5.x
License: Public Domain
Posted: Jun. 12, 2006
Updated: Feb. 11, 2008
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. The tag creates a new [os_process] type, opens a new bash shell, switches the current working directory to the folder from which the tag was called, and executes whatever command is passed to it. Requires [response_localfolder] and only loads if you are using the MacOS X version of Lasso Professional 8.5 or higher, and the [os_process] type is loaded.

Parameters

none


Sample Usage

shell('echo foo');

-> foo
						

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
24
25
26
27
if(
	lasso_version( -lassoversion) >= 8.5 
	&& lasso_version( -lassoplatform) >> 'Mac'
	&& lasso_tagexists('os_process')
);
	define_tag(
		'shell',
		-required='cmd',
		-privileged,
		-priority='replace',
		-description='Executes a single shell command via [os_process].'
	);
		local('shell') = os_process(
			'/bin/bash',
			array(
				'-c',
				'cd ' + response_localfolder + '; ' + #cmd
			)
		);
		
		local('out') = #shell->read;
		!#out->size ? #out = #shell->readerror;
		#shell->close;
		return(#out);
	/define_tag;
/if;

 

Related Tags



Comments

02/11/2008, Jason Huck
Updated
[shell] now returns the contents of stderr if stdout was empty.
02/11/2008, Pier Kuipers
Adding optional "readerror"
Having used this tag with great effect for some time now, I found just one problem with it - sometimes the required output from cli operations is strictly regarded as an error, in which case [shell] does not return anything. To solve this problem, I added -optional='osreaderror' parameter to the tag's definition, which is called just before #shell->close as follows: if(local_defined('osreaderror')); #out = #shell->readerror; /if; It does the trick for me, and you might consider updating your tag to include this option if you think it worthwhile :-)
Email:


Password:



Newest

Most Popular