This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
eastwood6510's profile picture

[Question] How to use console commands INSIDE of a program

Started by eastwood6510, 11 January 2013 - 02:00 PM
eastwood6510 #1
Posted 11 January 2013 - 03:00 PM
Ok so basically, I want to write a simple program that will delete a different program on the computer/turtle, then copy the updated program from a nearby disk.

Essentially I want to write a program for a turtle so I can update a program for an army of turtles without entering a ton of commands.
It would essentially be this:

delete otherProgram
cp disk/otherProgram /

Now, this will work in the console by just typing it in (obviously) but I want to put this in a program so that I can just type the name and it would do the lame repetitive typing for me. I mean, who wants to update the same program on 30 different turtles by hand all the time.

So, if anyone knows how to use console commands inside of a program, that would be very much appreciated!
Luanub #2
Posted 11 January 2013 - 03:11 PM
You use shell.run()

Here's an example using your cp example

shell.run("cp","disk/otherProgram","toNewFile")

Main thing to remember is to seperate the arguments with comma's.

It is probably best to stay away from using shell.run() to much however. There are API's that allow you to perform these same functions without running the external programs.


--to copy a file
fs.copy("fromFile","toFile")

--to delete
fs.delete("filePath")
remiX #3
Posted 11 January 2013 - 03:18 PM
You use shell.run()

Here's an example using your cp example

shell.run("cp","disk/otherProgram","toNewFile")

Main thing to remember is to seperate the arguments with comma's.

It is probably best to stay away from using shell.run() to much however. There are API's that allow you to perform these same functions without running the external programs.


--to copy a file
fs.copy("fromFile","toFile")

--to delete
fs.delete("filePath")

shell.run() arguments can be separated by spaces too.

shell.run("cp disk/otherProgram toNewFile")
will work.

Check out the fs api on the wiki:


fs.copy("fileToCopy", "newPath")
fs.move("fileToMove", "newPath")
fs.delete("fileToDelete")
-- etc..
eastwood6510 #4
Posted 11 January 2013 - 03:21 PM
Sweet! Thanks guys, just the info I needed
Luanub #5
Posted 11 January 2013 - 03:56 PM
shell.run() arguments can be separated by spaces too.

I keep forgetting that it has changed.. :unsure:/>
D3matt #6
Posted 11 January 2013 - 10:33 PM
Console commands are really just simple programs. You're much better off learning how they work so you can just put the code directly in your program instead of using shell.run.