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

using shell.run with arguements?

Started by caza1112, 29 January 2016 - 11:42 PM
caza1112 #1
Posted 30 January 2016 - 12:42 AM
So i was just playing around with a quarry program (for a mining turtle) and i was trying to use the file "start" to start
the file "q" while using arguements.

The program would q would run by typing "q 4" and you get the idea (it digs an extra block which i am aware of).

However when i run the file "startup" as follows, "start 2 4" it prints out "No such program" twice.

i would like it to run the code by:

start <how many times to run the program> <the arguement for the "q" program>

This is a screenshot of the error :)/>



thanks in advance :)/>
-caza1112
KingofGamesYami #2
Posted 30 January 2016 - 01:23 AM
It would look something like this:


local tArgs = {...} --#get the program arguments
for i = 1, tonumber( tArgs[ 1 ] ) do --#loop for the first argument number of times (will error if it isn't given a number!)
  shell.run( "q", unpack( tArgs, 2 ) ) --#run the program 'q', supply the rest of the arguments passed to this program
end

..at least in recent versions of computercraft. If you're on an older version which does not support multiple arguments to shell.run, you'd do something like this:


local tArgs = {...} --#get the program arguements
for i = 1, tonumber( tArgs[ 1 ] ) do --#loop for the first argument number of times (will error if it isn't given a number!)
  shell.run( "q " .. table.concat( tArgs, " ", 2 ) ) --#run the program 'q', concatenating the rest of the arguments (seperated by spaces) to form a single string
end
Edited on 30 January 2016 - 12:26 AM
caza1112 #3
Posted 30 January 2016 - 01:32 AM
Thanks KingOfGamesYami, the second piece of code worked perfectly, thank you very much man :)/>
local tArgs = {…}
for i = 1, tArgs[ 1 ] do
shell.run( "q " .. table.concat( tArgs, " ", 2 ) )
end