Difference between revisions of "Shell.run"

From ComputerCraft Wiki
Jump to: navigation, search
m
 
(8 intermediate revisions by 6 users not shown)
Line 1: Line 1:
 +
{{lowercase}}
 +
{{Function
 +
|name=shell.run
 +
|args= {{type|string}} program [, {{type|string}} args1, {{type|string}} args2, ...]
 +
|returns={{type|boolean}} success
 +
|api=shell
 +
|addon=ComputerCraft
 +
|desc=Runs ''program'' with as many specified arguments as are provided.<br><br>
 +
 +
Essentially takes all parameters passed to it and runs them as one line - for eg, shell.run("monitor","top","alongtimeago") is the same as shell.run("monitor top alongtimeago"), and you can use whichever syntax happens to suit you.<br><br>
 +
 +
See also: [[shell.openTab|shell.openTab()]]
 +
|examples=
 
{{Example
 
{{Example
|desc=shell.run(String programLocation, String arguments), This program is used to run a program with code instead of type. such as if you typed "myprogram test".
+
|desc=Runs the program "myProgram" with arguments "test" and "ing":
This does not produce a new line, and anything else printed or written after this will be on the same line.
+
|code= shell.run("myProgram", "test", "ing")
|code=shell.run("myprogram", "test")
+
|output=The program myProgram with the arguments "test" and "ing".
|output=Runs the program "myprogram" with arguments "test"
+
}}
 +
{{Example
 +
|desc=Runs the program "monitor" along with the other arguments set in "myTable":
 +
|code= local myTable = {"monitor","left","worm"}
 +
 +
shell.run( unpack(myTable) )
 +
}}
 
}}
 
}}
  
Here is a example how to run programs with custom input.
+
[[Category:API_Functions]]
 
+
stringArgs=read() -- You input a line of string, and each space makes a argument, such as "arg1 arg2". Argument 1 is "arg1".
+
shell.run("myprogram", stringArgs)
+
-- runs the program. myprogram would have to be located on the main directory of the computer for this to work.
+

Latest revision as of 07:30, 4 April 2014


Grid Redstone.png  Function shell.run
Runs program with as many specified arguments as are provided.

Essentially takes all parameters passed to it and runs them as one line - for eg, shell.run("monitor","top","alongtimeago") is the same as shell.run("monitor top alongtimeago"), and you can use whichever syntax happens to suit you.

See also: shell.openTab()
Syntax shell.run(string program [, string args1, string args2, ...])
Returns boolean success
Part of ComputerCraft
API shell

Examples

Grid paper.png  Example
Runs the program "myProgram" with arguments "test" and "ing":
Code
shell.run("myProgram", "test", "ing")
Output The program myProgram with the arguments "test" and "ing".



Grid paper.png  Example
Runs the program "monitor" along with the other arguments set in "myTable":
Code
local myTable = {"monitor","left","worm"}

shell.run( unpack(myTable) )