3 posts
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 ?
957 posts
Location
Web Development
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!
7083 posts
Location
Tasmania (AU)
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.
306 posts
Location
Mars
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
3 posts
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?
3057 posts
Location
United States of America
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
3 posts
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!!