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

Running commands on other computers via rednet

Started by 873Project, 30 October 2012 - 03:08 PM
873Project #1
Posted 30 October 2012 - 04:08 PM
Hi guys I'm wondering how / if you can make other computers run commands over rednet.
jag #2
Posted 30 October 2012 - 04:19 PM
Do you want to send a message that will be printed on a screen?
Or do you want to start a program wirelessly via rednet?

Or both?
873Project #3
Posted 30 October 2012 - 04:21 PM
Start a program wirelessly over rednet
remiX #4
Posted 30 October 2012 - 05:06 PM

while true do
event = os.pullEvent("rednet_message")
if event then
  id, msg, dist = rednet.recieve()
  if fs.exists(msg) then
	shell.run(msg)
  else
	return nil, "File does not exist!"
  end
end
end

Something like that I think.
873Project #5
Posted 30 October 2012 - 05:58 PM

while true do
event = os.pullEvent("rednet_message")
if event then
  id, msg, dist = rednet.recieve()
  if fs.exists(msg) then
	shell.run(msg)
  else
	return nil, "File does not exist!"
  end

Thanks !
ChunLing #6
Posted 30 October 2012 - 06:37 PM
You'll want to strip off (and repackage) any command line parameters too. So:
id, msg, dist = rednet.recieve()
local t_param,ndx = {},1
for v in params:gmatch("%w+") do tprm[ndx] = v ndx = ndx+1 end
if fs.exists(t_param[1]) then
    shell.run(unpack(t_param))
return t_param[1].." executed"
else --whatever you want to say
end
873Project #7
Posted 31 October 2012 - 06:14 PM
You'll want to strip off (and repackage) any command line parameters too. So:
id, msg, dist = rednet.recieve()
local t_param,ndx = {},1
for v in params:gmatch("%w+") do tprm[ndx] = v ndx = ndx+1 end
if fs.exists(t_param[1]) then
    shell.run(unpack(t_param))
return t_param[1].." executed"
else --whatever you want to say
end
Ok thanks for the help!
ChunLing #8
Posted 31 October 2012 - 10:56 PM
Oh, I didn't convert a couple of my identifiers in the above post. "params:gmatch("%w+")" should be "msg:gmatch("%w+")", and "tprm[ndx]" should be "t_param[ndx]".

Here is a question, why do I convert identifiers? It can be such a hassle. And I'm so bad at it.