Jump to content




opening text files to edit


14 replies to this topic

#1 DusterTheFirst

  • Members
  • 40 posts

Posted 22 June 2016 - 05: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.

#2 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 22 June 2016 - 05: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'?

#3 Lignum

  • Members
  • 558 posts

Posted 22 June 2016 - 05:38 PM

View PostKingofGamesYami, on 22 June 2016 - 05:31 PM, said:

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 by Lignum, 22 June 2016 - 10:29 PM.


#4 Sewbacca

  • Members
  • 450 posts
  • LocationStar Wars

Posted 22 June 2016 - 10:17 PM

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


#5 Lemmmy

  • Members
  • 218 posts

Posted 22 June 2016 - 10:30 PM

View PostSewbacca, on 22 June 2016 - 10:17 PM, said:

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

#6 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 23 June 2016 - 08:58 AM

View PostLemmmy, on 22 June 2016 - 10:30 PM, said:

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.

#7 DusterTheFirst

  • Members
  • 40 posts

Posted 23 June 2016 - 10:04 AM

View PostKingofGamesYami, on 22 June 2016 - 05:31 PM, said:

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

#8 DusterTheFirst

  • Members
  • 40 posts

Posted 23 June 2016 - 10:16 AM

View PostLignum, on 22 June 2016 - 05:38 PM, said:

View PostKingofGamesYami, on 22 June 2016 - 05:31 PM, said:

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?

#9 Lignum

  • Members
  • 558 posts

Posted 23 June 2016 - 10:40 AM

View PostDusterTheFirst, on 23 June 2016 - 10:16 AM, said:

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.

#10 DusterTheFirst

  • Members
  • 40 posts

Posted 23 June 2016 - 10:45 AM

also is it possible to save a file while it is opened in fs(API)?

#11 Sewbacca

  • Members
  • 450 posts
  • LocationStar Wars

Posted 23 June 2016 - 11:13 AM

View PostDusterTheFirst, on 23 June 2016 - 10:45 AM, said:

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.

#12 DusterTheFirst

  • Members
  • 40 posts

Posted 23 June 2016 - 11:24 AM

View PostSewbacca, on 23 June 2016 - 11:13 AM, said:

View PostDusterTheFirst, on 23 June 2016 - 10:45 AM, said:

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?

#13 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 23 June 2016 - 11:58 AM

View PostDusterTheFirst, on 23 June 2016 - 10:45 AM, said:

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.

#14 Sewbacca

  • Members
  • 450 posts
  • LocationStar Wars

Posted 23 June 2016 - 12:04 PM

View PostDusterTheFirst, on 23 June 2016 - 11:24 AM, said:

View PostSewbacca, on 23 June 2016 - 11:13 AM, said:

View PostDusterTheFirst, on 23 June 2016 - 10:45 AM, said:

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 by Sewbacca, 23 June 2016 - 12:05 PM.


#15 DusterTheFirst

  • Members
  • 40 posts

Posted 23 June 2016 - 02: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)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users