FANDOM


Runs a shell command and returns its output. It blocks livecode until the command is completed, if you don't want to block livecode, use open process instead.

Syntax:

the shell of commandLine
shell(commandline) 

Examples:

put shell("ls -l *.txt") -- returns a listing of the current dir on Unix
put shell(field "Command")
put shell("attrib main.rev +R")

Use the shell function to execute a command line.

The commandLine is a string or an expression that evaluates to a string.

The shell function returns a string.

The commandLine must be a valid shell command on the current operating system. Use the shellCommand property to set the shell you want to use. The command is executed in the current defaultFolder.

If you use a file path in the shell command on a Windows system, the file path must be in Windows form, not the Unix-style file paths that LiveCode uses internally.

The value returned by the shell function is the result of the commandLine, including any error messages the commandLine generates. (On Unix systems, the stdout and stderr are combined to create the return value.) The current handler pauses until the shell returns its result. If the command was successful but did not return anything, the shell function returns empty.

The result is set to the shell command's exit code.

To prevent a console window from appearing when the shell command is executed, set the hideConsoleWindows property to true.

If you are having problems with the shell function, try executing the commandLine at your operating system's shell prompt. (For example, on an OS X system, try executing the commandLine in the Terminal window.) If a commandLine does not work at the shell prompt, it won't work with the shell function either, so trying this can be useful when debugging.


The shell function returns empty if a shell command (that does not normally return any data) was successful. In previous versions, the shell function returned zero in this case.

NoteEdit

Mac OS X note: the environment variables which are available in the shell function may not be the same as those available in the Terminal app. For instance, it may be necessary to update the $PATH variable to make some commands available to the shell function.

See Also: screenName Function, launch Command, hideConsoleWindows Property

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.