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

Is there an equivalent for $PATH in CraftOs?

Started by lincore, 12 December 2012 - 10:28 PM
lincore #1
Posted 12 December 2012 - 11:28 PM
So I got into cc recently and I'm having a blast so far, but I'm wondering: Is there a way to execute programs without either traversing the directory tree or specifying the path?
Ideally I'd like to have a list of directories that the shell checks for an executable by the given name.
CoolisTheName007 #2
Posted 13 December 2012 - 12:25 AM
I could adapt loadreq to that; in fact I'm gonna do it.
CoolisTheName007 #3
Posted 13 December 2012 - 01:12 AM
Ok, updated the loadreq with a simple function and some changes that allow to use it to run files as normally.
E.g.:

---runs filepath path with args ... using the same rules as @require for determining the globs to uses
--e.g.
--[[
os.loadAPI('APIS/loadreq')
loadreq.vars.paths=loadreq.vars.paths..';myFolder'
--or
REQUIRE_PATH='myFolder'
--ect
loadreq.run_lua('subFolder/subsubFolder/myFile.lua',arg1,arg2,...)
]]
KaoS #4
Posted 13 December 2012 - 02:30 AM
use the command shell.setPath(dirs separated by ';'s ) it is the equivalent of %path% in cmd


local function add(dir)
  if fs.exists(dir) and fs.iDir(dir) then
	shell.setPath(shell.getPath..';'..shell.resolve(dir))
  end
end
CoolisTheName007 #5
Posted 13 December 2012 - 05:39 AM
snip

How dumb of me to misinterpret the whole thing.. :blink:/>
KaoS #6
Posted 13 December 2012 - 06:44 AM
snip

we all derp. chilled stuff
lincore #7
Posted 14 December 2012 - 10:35 PM
use the command shell.setPath(dirs separated by ';'s ) it is the equivalent of %path% in cmd


local function add(dir)
  if fs.exists(dir) and fs.iDir(dir) then
	shell.setPath(shell.getPath..';'..shell.resolve(dir))
  end
end
Just what I was looking for, thank you!

[…]
How dumb of me to misinterpret the whole thing.. :blink:/>
After all we're only humans == derpy :~)
Thanks for trying to help me out.