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

Question: Programs making Programs

Started by Glimprime, 03 January 2013 - 04:17 PM
Glimprime #1
Posted 03 January 2013 - 05:17 PM
Im trying to write a program that will copy programs (that i specify, or all) from a disk to a turtle.

I know that if im just in the base craftOS interface i can do <cp disk/<program> <program> but when i go to my program and type cp disk/<program> <program> that dosnt work…

so ive been looking at using fs.copy() but that dosnt seam to work either…and i dont see anything in the shell api thats jumping out at me as copy stuff…so now im stuck.

help?
theoriginalbit #2
Posted 03 January 2013 - 05:31 PM
Ok firstly the fs.copy should work if you are providing the 2 file paths and if both exist.

Secondly the other option is to use shell.run … shell.run is used similar to how you type it into the terminal you would do it like this
shell.run( "cp", file1, file2 )

EDIT: Where file1 and file2 are strings of the file paths.
Glimprime #3
Posted 03 January 2013 - 05:46 PM
im still messing with fs.copy

im trying to use the program load to copy a program called line to the turtles root directory ive only been using the 1 line for the code so if there is more that i need to do…

so far ive tried

fs.copy(disk/line, line)
fs.copy(disk/line line)
shell.run(cp disk/line line) <which is what i have been using on the interface
shell.run(cp,disk/line,line)
shell run("cp", disk/line, line)



still nothing…quite a few times ive recieved the <attempt to preform arithmatic __div on table and nil> which I think means i tried to divide by zero (or nothing)

so im still kinda lost…

if you know how to write this program…be my guest, id love to pick it apart and see how it works
theoriginalbit #4
Posted 03 January 2013 - 06:02 PM
im still messing with fs.copy

im trying to use the program load to copy a program called line to the turtles root directory ive only been using the 1 line for the code so if there is more that i need to do…

so far ive tried

fs.copy(disk/line, line)
fs.copy(disk/line line)
shell.run(cp disk/line line) <which is what i have been using on the interface
shell.run(cp,disk/line,line)
shell run("cp", disk/line, line)



still nothing…quite a few times ive recieved the <attempt to preform arithmatic __div on table and nil> which I think means i tried to divide by zero (or nothing)

so im still kinda lost…

if you know how to write this program…be my guest, id love to pick it apart and see how it works

Ok so the problem is the file paths need to be a string, so surrounded with "
So it sees it as your trying to divide disk by line

As for writing this program it's one line.

fs.copy( "disk/line", "/" )

If its for a like production facility, you put this in a startup file on a disk drive, place a turtle beside the disk drive and use a computer to turn the turtle on, the disk's startup it copy the file.
Glimprime #5
Posted 03 January 2013 - 06:10 PM
If its for a like production facility, you put this in a startup file on a disk drive, place a turtle beside the disk drive and use a computer to turn the turtle on, the disk's startup it copy the file.

you read my mind :D/>

IT WORKS! thank you, thank you…
you have made my night
theoriginalbit #6
Posted 03 January 2013 - 06:25 PM
Suggestion:
On disk drive:

if not fs.exists( "/startup" ) then -- just been placed
  fs.copy( "disk/line", "/startup" )
  -- refuel here if u have a version that needs it
  turtle.forward() -- moves it away from the disk drive
  os.reboot() -- runs its local startup, not the disk one
end
On computer that turns on turtle

while true do
if peripheral.isPresent("left") then -- or whatever side the turtle will be
peripheral.call("left", "turnOn")
end
sleep(0.1)
end

EDIT: Your welcome :)/>