Jump to content




using shell.run with arguements?


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

#1 caza1112

  • Members
  • 14 posts

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 :)

Posted Image

thanks in advance :)
-caza1112

#2 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

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 by KingofGamesYami, 30 January 2016 - 01:26 AM.


#3 caza1112

  • Members
  • 14 posts

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





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users