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

shell.run multiple arguments

Started by xen0n, 07 August 2013 - 05:33 AM
xen0n #1
Posted 07 August 2013 - 07:33 AM
I'm using a program that can launch other programs when it receives an instruction from the main server.
To execute these programs I'm using shell.run. My problem is that I have different programs with a different number of argument, so sometimes shell.run needs 2 arguments and sometimes 3.

When the main program receives the instruction it stores the program name + parameters in a table, later it runs a function "run(table)" that receives the instruction table and runs shell.run with the arguments in the table. How do I give shell.run an unknown number of arguments from the table?

I've tried it this way but it didn't work.

function run(table)
  runCommand = ""
  for i,v in ipairs(table) do
	if i == 1 then
	  runCommand = runCommand..v[1]
	else
	  runCommand = runCommand..,..v[i]
	end
  end
  shell.run(runCommand)
end
Lyqyd #2
Posted 07 August 2013 - 07:39 PM
Split into new topic.


shell.run(unpack(tableOfCommand))

Of course, this would work just as well (though the above may be faster):


shell.run(table.concat(tableOfCommand, " "))