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

Shell.run() problem

Started by LNETeam, 31 May 2013 - 10:52 AM
LNETeam #1
Posted 31 May 2013 - 12:52 PM
Hello Computercraft Forums!


I come today with an issue I'd like help with. I am currently working on a very big project and I'm focusing on a certain part. The security. I have a function that is designed to terminate a session and add a blacklist or timeout period before out login program can initiate again. Here is what I have (segment from our security code):

function block(ids,reg)
if not ids then return false end
if not fs.exists("blacklist") and reg==true then
local blockd = tostring(ids)
local blockStart = tostring(os.time())
block="block = {id="..blockd..",time=5,start="..blockStart.."}"
han = io.open("blacklist","w")
han:write(block)
han:close()
else
if fs.exists("blacklist") then
shell.run("blacklist")
add = block.time+block.start
fin = add-os.time()
if block.id==ids and not os.time()==add then
error("You are currently prohibited from CCraftBox. Please wait "..fin)
else
fs.delete("blacklist")
end
end
end
end
Now the function writes the blacklist fine, the file is created and all, but when the second part is called(at the right time of course; which means the file IS existent), I get an error at the
shell.run("blacklist")
. The error is the attempt to index ? (a nil value). I have no idea why this is happening. The blacklist file is there, it is spelled correctly. when I delete the blacklist, it functions as normal until another one is generated from the maxxed out try(s) from out login. Please help me and thank you for your time!
tonkku107 #2
Posted 31 May 2013 - 12:56 PM
try

shell.run(blacklist)
without ""

Nope
W00dyR #3
Posted 31 May 2013 - 01:01 PM
try

shell.run(blacklist)
without ""

The shell.run() function reads strings. The only way this would work if the op declared blacklist = "blacklist" but that would be the exact same as shell.run("blacklist") anyway.

@op: Does the program run fine when it reads a blacklist file that exists before the program is ran? As in does it error "shell.run("blacklist")" when it was not created through the program?
Exerro #4
Posted 31 May 2013 - 01:17 PM
The error attempt to index ( a nil value ) would suggest either the code inside crashes or shell is nil. If you are messing around with environments I think using _G doesn't include shell but getfenv( ) does.
MysticT #5
Posted 31 May 2013 - 02:30 PM
The code is inside an api, right? You can't use the shell api in apis, it's not defined in that environment. You can use os.run instead.
Yevano #6
Posted 31 May 2013 - 03:11 PM
What MysticT said is correct. I would, however, just load and compile the file manually. You may not have the same problems I had when using os.run in an API context, but it wasn't an option for me.

You could do something similar to:

function runFile(path, …) loadstring(fs.open(path, "r").readAll())({…}) end
LNETeam #7
Posted 04 June 2013 - 07:35 AM
I tried os.run(), same problem
Yevano #8
Posted 04 June 2013 - 11:20 AM
I tried os.run(), same problem

Try what I said at the end of my post. Also, is it the exact same error, or is it different?
PixelToast #9
Posted 04 June 2013 - 11:58 AM
you could have just asked me on skype xD
this isnt a verry good method of saving stuff
in http://ptoast.tk/hl/ccraftboxui i use a settings table and save / modify it when neccicary
it used my saveprefs and readprefs function wich is found here: http://ptoast.tk/hl/apis/infutil