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

opening text files to edit

Started by DusterTheFirst, 22 June 2016 - 04:14 PM
DusterTheFirst #1
Posted 22 June 2016 - 06:14 PM
I have a complex system with interconnected computers that share data using text files stored on a floppy.
I am trying to make a computer that can just edit that text(like a config file) when it boots, and that is its only purpose.
I have searched far and wide-ish and have yielded no results.

I Have Only Tried Running

multishell.launch({}, "edit disk/todo.txt")
and other arrangements of the words. like

multishell.launch({}, "edit", "disk/todo.txt")
all return "FILE NOT FOUND"

I Want To Use Multishell So The Computer Can Tab Through Different Open Text Files And Edit Them. Any Help Would Be Greatly Appreciated.
KingofGamesYami #2
Posted 22 June 2016 - 06:31 PM
What happens if you run
'edit disk/todo.txt' in the shell?

Does it actually exist, or is it something like 'disk2/todo.txt'?
Lignum #3
Posted 22 June 2016 - 06:38 PM
What happens if you run
'edit disk/todo.txt' in the shell?

Does it actually exist, or is it something like 'disk2/todo.txt'?

Edit would open anyway.

The file that's not being found is the edit program. This is because multishell.launch takes absolute paths, contrary to shell.run, which is relative to the current directory and the path.

So you could either do:

multishell.launch({ shell = shell }, "rom/programs/edit", "disk/todo.txt")
or:

multishell.launch({ shell = shell }, shell.resolveProgram("edit"), "disk/todo.txt")
Edited on 22 June 2016 - 09:29 PM
Sewbacca #4
Posted 22 June 2016 - 11:17 PM
try:

local tEnv = {}
tEnv._ENV = tEnv
setmetatable(tEnv, {__index = _G})
multishell.launch(tEnv, '/rom/programs/edit', '/disk/todo.txt')
Lemmmy #5
Posted 22 June 2016 - 11:30 PM
try:

local tEnv = {}
tEnv._ENV = tEnv
setmetatable(tEnv, {__index = _G})
multishell.launch(tEnv, '/rom/programs/edit', '/disk/todo.txt')

how long have you been in isolation to think that this is ok
Bomb Bloke #6
Posted 23 June 2016 - 09:58 AM
how long have you been in isolation to think that this is ok

The same could be said of your own comment. If you want to correct someone, at least present a better solution.

Speaking of which.
DusterTheFirst #7
Posted 23 June 2016 - 11:04 AM
What happens if you run
'edit disk/todo.txt' in the shell?

Does it actually exist, or is it something like 'disk2/todo.txt'?

yes it actually exists it has comments on the first 2 lines
DusterTheFirst #8
Posted 23 June 2016 - 11:16 AM
What happens if you run
'edit disk/todo.txt' in the shell?

Does it actually exist, or is it something like 'disk2/todo.txt'?

Edit would open anyway.

The file that's not being found is the edit program. This is because multishell.launch takes absolute paths, contrary to shell.run, which is relative to the current directory and the path.

So you could either do:

multishell.launch({ shell = shell }, "rom/programs/edit", "disk/todo.txt")
or:

multishell.launch({ shell = shell }, shell.resolveProgram("edit"), "disk/todo.txt")

hey that worked :D/>
what exactly does "shell = shell" do?
Lignum #9
Posted 23 June 2016 - 11:40 AM
hey that worked :D/>
what exactly does "shell = shell" do?

It allows edit to access the shell API. The function Bomb Bloke mentioned, shell.openTab, does this for you.
DusterTheFirst #10
Posted 23 June 2016 - 11:45 AM
also is it possible to save a file while it is opened in fs(API)?
Sewbacca #11
Posted 23 June 2016 - 12:13 PM
also is it possible to save a file while it is opened in fs(API)?

Nope, because Java allows just one handle per file at one time and CC is based on Java.
Also just the fs(API) can open files, so with io(API) would it fail either.
DusterTheFirst #12
Posted 23 June 2016 - 12:24 PM
also is it possible to save a file while it is opened in fs(API)?

Nope, because Java allows just one handle per file at one time and CC is based on Java.
Also just the fs(API) can open files, so with io(API) would it fail either.
what if i periodicly opened and closed the file in fs(api) could i edit the file between then?
Bomb Bloke #13
Posted 23 June 2016 - 12:58 PM
also is it possible to save a file while it is opened in fs(API)?

Do you mean you want to re-write a file's content from elsewhere while it's open in edit?

You could, but I don't see why you'd want to, and it wouldn't alter the copy that edit already has loaded into RAM. It doesn't watch the drive for changes.
Sewbacca #14
Posted 23 June 2016 - 01:04 PM
also is it possible to save a file while it is opened in fs(API)?

Nope, because Java allows just one handle per file at one time and CC is based on Java.
Also just the fs(API) can open files, so with io(API) would it fail either.
what if i periodicly opened and closed the file in fs(api) could i edit the file between then?

After closing the file, the handle is useless and you have to create a new one, so yes, but If you want to edit a file at the same time, why you don't do this:

local h = fs.open(...)
local file = loadfile('aFile', {handle = h}) --Note that in this case, the program have just access to the handle.
parallel.waitForAll(file, main)

File is the file which needs the handle and you set the environment variable handle to h, so in the file, handle.write(…) would work.
Main is your program. Both programs have access to the handle.
Edited on 23 June 2016 - 11:05 AM
DusterTheFirst #15
Posted 23 June 2016 - 03:12 PM
I am trying to make a todo system where i can add or remove things from the lis. i thought that having a file that i edit with all the todos on it that would just be printed to a montor is the easyest rout but as this shows it was a far fetched idea.

so i guess my question now is how would i make a simple todo system that i could implement in my program that would be simple and edited from the monitor(like deleting them)