I run a torch script from my linux shell using the th command. This torch script accepts two input parameters:
th torch_script.lua input_parameter1 input_parameter2
Now I want to run this script through the Torch shell. To do this, I need to use the dofile command. But in this case, I do not know how to pass the input parameters input_parameter1 and input_parameter2 .
In Torch, how do I pass some input parameters to the dofile run dofile ?
EDIT : Here is the code I'm trying to run. I can't run it correctly, maybe you can tell me why
Contents of external_command.lua:
local arg = arg or {...} input_parameter = arg[1] print("input_parameter ".. input_parameter);
On the shell:
$th th> tempFunc = load "external_command.lua" th> tempFunc("try") [string "_RESULT={tempFunc("try")}"]:1: attempt to call global 'tempFunc' (a nil value) stack traceback: [string "_RESULT={tempFunc("try")}"]:1: in main chunk [C]: in function 'xpcall' /home/davide/torch/install/share/lua/5.1/trepl/init.lua:630: in function 'repl' ...vide/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:185: in main chunk [C]: at 0x004064d0
EDIT 2 : I tried the solution sent by TonyHsu, but that still doesn't work. That's what I'm doing.
I define a runfile() function in a script called runfile.lua that contains the following code:
function runfile(scriptName, input) opt = nil arg = input dofile(scriptName) end
Then I use an external_command.lua script, which I previously defined as an input parameter to scriptName for this function:
th> scriptName = "external_command.lua" th> require './runfile.lua' th> runfile(scriptName, "Hello world");
Unfortunately, also in this case I get an error message:
external_command.lua:4: attempt to concatenate global 'input_parameter' (a nil value) stack traceback: external_command.lua:4: in main chunk [C]: in function 'dofile' /home/davide/torch/temp/runfile.lua:4: in function 'runfile' [string "runfile(scriptName, "Hello world");"]:1: in main chunk [C]: in function 'xpcall' /home/davide/torch/install/share/lua/5.1/trepl/init.lua:648: in function 'repl' ...vide/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:185: in main chunk [C]: at 0x004064d0