Posted 10 January 2013 - 03:27 PM
Hi everyone, I need help for a project of mine.
Let's say I have a file on "mainComputer". I want to copy this file to a remote turtle, via rednet
I have two programs : one on the mainComputer, and one on turtle1.
the program on mainComputer :
the program on the turtle :
Almost everything works fine : the shell command to copy the file works fine. I can open it and start writing in it.
The probelm, I think is the formating of the content of the file I want to copy.
In "test1", there are only two simple lines for now :
on the copied version of the file the only content is : "print" , which, I guess, is just the first word of the content I want to transfer …..
I tried different ways to format it.
I tried with Fs API, IO API.
Don't know what to try anymore.
I hope I am being clear.
Let's say I have a file on "mainComputer". I want to copy this file to a remote turtle, via rednet
I have two programs : one on the mainComputer, and one on turtle1.
the program on mainComputer :
local targs = {...}
--open file in read mode
file = io.open(targs[1],"r")
-- read all the file and format the content. ( I tried without 'string.format() ...' doesn't work either )
content = string.format('%q',file:read('*a'))
print("content ==== "..content)
cmd = ('copyFile '..targs[1]..' '..content)
--send the command as a rednet message to the turtle
rednet.send(48,cmd)
I fire it by typing : copyFileMaster "test1" – "test1" is a file present on my mainComputerthe program on the turtle :
local targs = {...}
cmd = ('copy "startup" '..targs[1]) -- this command works fine it copies startup with a new name ( I didn't know how to create a new file otherwise ....)
print (cmd)
shell.run(cmd)
file = io.open(targs[1],"w")
file:write(targs[2]) -- it's the part that does not work at all .... targs[2]
file:close()
Almost everything works fine : the shell command to copy the file works fine. I can open it and start writing in it.
The probelm, I think is the formating of the content of the file I want to copy.
In "test1", there are only two simple lines for now :
print ("hello")
print ("world")
on the copied version of the file the only content is : "print" , which, I guess, is just the first word of the content I want to transfer …..
I tried different ways to format it.
I tried with Fs API, IO API.
Don't know what to try anymore.
I hope I am being clear.