1 posts
Posted 22 October 2017 - 06:11 AM
Hello,
i wan't to list out an directory on my Monitor i tried the following:
monitor = peripheral.wrap("right")
monitor.clear()
monitor.setTextScale(2)
monitor.setCursorPos(1,1)
local directory = shell.run("dir")
monitor.write(directory)
But then i just get an Boolean, true.
Any help?
7083 posts
Location
Tasmania (AU)
Posted 24 October 2017 - 08:56 AM
shell.run() returns whether the target script executed or not. It doesn't gather terminal output from that script. Calling
term.redirect(monitor) and then just doing shell.run("dir") should "work", though.
62 posts
Location
Sweden
Posted 25 October 2017 - 07:35 AM
Edited on 25 October 2017 - 05:36 AM
2427 posts
Location
UK
Posted 25 October 2017 - 12:43 PM
1852 posts
Location
Sweden
Posted 30 October 2017 - 03:13 PM
And to extend this:
http://www.computercraft.info/wiki/Fs.listfs.list returns a table, so if you want to print all the files in the directory you need to loop through the table.
--# Find the monitor using peripheral.find
local monitor = peripheral.find( "monitor" )
local sPath = "/"
--# Setup the monitor
monitor.setTextScale(2)
monitor.setCursorPos(1, 1)
monitor.clear()
--# Redirect all output to the monitor
term.redirect( monitor )
--# Loop through the table and print all the files in the given directory
for _, name in ipairs(fs.list(sPath)) do
print( name )
end