Jump to content




Shell.run

command lua

6 replies to this topic

#1 Roberto80

  • Members
  • 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 ?

#2 HPWebcamAble

  • Members
  • 933 posts
  • LocationWeb Development

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!

#3 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (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.

#4 Nothy

  • Members
  • 250 posts
  • LocationMars

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 Roberto80

  • Members
  • 3 posts

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

Sorry for this question, but how i use it?

#6 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited 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


#7 Roberto80

  • Members
  • 3 posts

Posted 06 March 2016 - 06:19 PM

 KingofGamesYami, on 05 March 2016 - 07:17 PM, said:

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!!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users