Jump to content




Copying multiple programs by a function


  • You cannot reply to this topic
7 replies to this topic

#1 Neekow

  • Members
  • 55 posts

Posted 10 April 2013 - 02:52 AM

Hi everyone =)

in a first time:
- I'm french and my english isn't perfect, i hope you will under stand what i'm doing and my question ^^
- I totally forgot from where i took this part of program, as i hate to copy without tell from where i take the code, if you recognize the code, tell me, i'll put the source ;) (only thing i remember: i took it from a startup/instal of an OS ...)


So, here we go:
i'm doing a multiple part programs (as an OS), but i want that all parts "installed" when you run the startup (still as an OS). So i looked many codes and found:


root = "http://pastebin.com/raw.php?i=18bq095q/"
file = "startup"	  

local response = http.get(root..file)
		if response then
				while response do
						local sResponse = response.readAll()
						response.close()
						cache = shell.resolve( file )
						local file = fs.open( cache, "w" )
						file.write( sResponse )
						file.close()
						response = nil
				end
		end
os.reboot()

But i'm always copying the pastebin's page source code ...

How can i fix that? =/

#2 LordIkol

  • Members
  • 197 posts
  • LocationSwitzerland

Posted 10 April 2013 - 04:10 AM

why you not just do this
then inside the startup file you can do the same for all the oder files

root = "18bq095q"
file = "startup"

pastebin get root file

then you could add a table with all the pastebin codes and the relevant name and run a loop like

local myprograms = {"editor", "whatever", "idontknow"}
local mypastebins = {"18bq095q", "13n083q", "12345"}

for i = 1,myprograms do 
pastebin get myprograms[i] mypastebins[i]
end

just as example

#3 Neekow

  • Members
  • 55 posts

Posted 10 April 2013 - 04:46 AM

View PostLordIkol, on 10 April 2013 - 04:10 AM, said:

why you not just do this
then inside the startup file you can do the same for all the oder files

root = "18bq095q"
file = "startup"

pastebin get root file

bios:338: [string "startuplite3"]:4: '=' expected

=(

#4 LordIkol

  • Members
  • 197 posts
  • LocationSwitzerland

Posted 10 April 2013 - 05:23 AM

sorry should be

root = "18bq095q"
file = "startup"

shell.run("pastebin", "get", root, file)


#5 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 10 April 2013 - 05:38 AM

You're trying to use http.get url as the url WITH the file name!

local url = "http://pastebin.com/raw.php?i=18bq095q/"
local fileName = "startup"          

local response = http.get(url)
if response then
	local file = fs.open( file, "w" )
	file.write( response.readAll() )
	file.close()
	response.close()
else
	print("Failed!")
end
os.reboot()


#6 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 10 April 2013 - 05:51 AM

I would like to point out that the OP says that the problem is that the pastebin source is being downloaded......

The reason for that is because this
http://pastebin.com/raw.php?i=18bq095q/
cannot have a / on the end, or 'startup' (which you are doing with http.get(root..file))
if you change it to
root = "http://pastebin.com/raw.php?i=18bq095q"
and
local response = http.get(root)

Also I would like to say that to all you that told OP to use the pastebin program, this is not a fix to the problem, yes it is a way to get around it, but it's not a fix... and part of the reason most 'good' OS installers do not use the pastebin program is because the program prints out information which can ruin GUIs and/or just look bad...

#7 Smiley43210

  • Members
  • 204 posts

Posted 10 April 2013 - 09:42 AM

View PostremiX, on 10 April 2013 - 05:38 AM, said:

You're trying to use http.get url as the url WITH the file name!

local url = "http://pastebin.com/raw.php?i=18bq095q/"
local fileName = "startup"		  

local response = http.get(url)
if response then
	local file = fs.open( file, "w" )
	file.write( response.readAll() )
	file.close()
	response.close()
else
	print("Failed!")
end
os.reboot()
Fixed incorrect variable name
local file = fs.open( fileName, "w" )


#8 LordIkol

  • Members
  • 197 posts
  • LocationSwitzerland

Posted 10 April 2013 - 06:51 PM

View Posttheoriginalbit, on 10 April 2013 - 05:51 AM, said:

I would like to point out that the OP says that the problem is that the pastebin source is being downloaded......

The reason for that is because this
http://pastebin.com/raw.php?i=18bq095q/
cannot have a / on the end, or 'startup' (which you are doing with http.get(root..file))
if you change it to
root = "http://pastebin.com/raw.php?i=18bq095q"
and
local response = http.get(root..file)

Also I would like to say that to all you that old OP to use the pastebin program, this is not a fix to the problem, yes it is a way to get around it, but it's not a fix... and part of the reason most 'good' OS installers do not use the pastebin program is because the program prints out information which can ruin GUIs and/or just look bad...

Hm, good point actually maybe i should try to fix the problem first before posting workaround... and good to know about the pastebin program, will keep this in mind.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users