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

Shell.run

Started by Roberto80, 27 February 2016 - 10:36 AM
Roberto80 #1
Posted 27 February 2016 - 11:36 AM
Hello. I use "Shell.run" in order to open some program from my program . However, it bothers me that is constantly being written messages that speak as a program is executed . For example, I do so to carry out a program with arguments pastebin get 44hfhroe3 test123. In my program written message "Connecting to pastebin … Sucess … Saved as test123" How to make sure that these messages were not? That they did not write and do not interfere with the implementation of the program ?
HPWebcamAble #2
Posted 27 February 2016 - 10:26 PM
Hello. I use "Shell.run" in order to open some program from my program . However, it bothers me that is constantly being written messages that speak as a program is executed . For example, I do so to carry out a program with arguments pastebin get 44hfhroe3 test123. In my program written message "Connecting to pastebin … Sucess … Saved as test123" How to make sure that these messages were not? That they did not write and do not interfere with the implementation of the program ?

shell.run(), as you probably know, runs a program as if you had typed it into the command line. Which includes printing text to the screen.

You can redirect the terminal to an invisible window, but that isn't the 'proper' way.


You can look into the pastebin program to see how it works. For convince, here's a link to it.
Try to implement it into your program, without the prints or shell.run. Feel free to ask if you aren't sure where to start!
Bomb Bloke #3
Posted 29 February 2016 - 06:49 AM
The really simple workaround is to define an invisible window, redirect to that, and then redirect back again once you're done.
Nothy #4
Posted 03 March 2016 - 08:02 AM
if you'd fancy a silent downloader, it's really simple to write.

local download = function(code, location)
  url = http.get("https://www.pastebin.com/raw/"..code)
  f = fs.open(location,"w") --#opens file in write mode, has to be specified with location
  f.write(url.readAll()) --#reads every byte of url and writes it to location
  f.close() --# always close the file >:c
  return true --#return true so function can be used in ifs
end

Roberto80 #5
Posted 05 March 2016 - 02:15 PM
if you'd fancy a silent downloader, it's really simple to write.

local download = function(code, location)
  url = http.get("https://www.pastebin.com/raw/"..code)
  f = fs.open(location,"w") --#opens file in write mode, has to be specified with location
  f.write(url.readAll()) --#reads every byte of url and writes it to location
  f.close() --# always close the file >:c
  return true --#return true so function can be used in ifs
end

Sorry for this question, but how i use it?
KingofGamesYami #6
Posted 05 March 2016 - 07:17 PM
It'd be something like this:

download( "44hfhroe3", "test123" ) --#took the stuff from your OP

However, his code isn't optimal. It uses global variables (which is slower and pollutes _G), and doesn't close the web handle. Plus, he never checked to see if the http get request was sucessful, meaning it could error.


--#better download function
local function downloadFromPastebin( pasteid, filepath ) --#more descriptive variable names
  local handle = http.get( "http://www.pastebin.com/raw/" .. pasteid ) --#sometimes CC has problems with https
  if handle then --#if the request succeeded
    local file = fs.open( filepath, "w" )
    file.write( handle.readAll() )
    file.close()
    handle.close() --#always close web handles!
    return true --#we succeeded, return true
  end
  return false --#it didn't work, return false
end
Roberto80 #7
Posted 06 March 2016 - 06:19 PM
It'd be something like this:

download( "44hfhroe3", "test123" ) --#took the stuff from your OP

However, his code isn't optimal. It uses global variables (which is slower and pollutes _G), and doesn't close the web handle. Plus, he never checked to see if the http get request was sucessful, meaning it could error.


--#better download function
local function downloadFromPastebin( pasteid, filepath ) --#more descriptive variable names
  local handle = http.get( "http://www.pastebin.com/raw/" .. pasteid ) --#sometimes CC has problems with https
  if handle then --#if the request succeeded
	local file = fs.open( filepath, "w" )
	file.write( handle.readAll() )
	file.close()
	handle.close() --#always close web handles!
	return true --#we succeeded, return true
  end
  return false --#it didn't work, return false
end
Thank you!!