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 ?
0
6 replies to this topic
#1
Posted 27 February 2016 - 11:36 AM
#2
Posted 27 February 2016 - 10:26 PM
Roberto80, on 27 February 2016 - 11:36 AM, said:
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!
#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
#5
Posted 05 March 2016 - 02:15 PM
Nothy, on 03 March 2016 - 08:02 AM, said:
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
#6
Posted 05 March 2016 - 07:17 PM
It'd be something like this:
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.
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
#7
Posted 06 March 2016 - 06:19 PM
KingofGamesYami, on 05 March 2016 - 07:17 PM, said:
It'd be something like this:
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.
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
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users