0

I have a lua-script, named "program.lua". I start this script as 'lua /path/to/program.lua' and I get specific CLI provided by the script:

bash $ /usr/bin/lua /path/to/program.lua
Usage: 
  help   - help
  quit   - quit
  do_get - get data
script> _

In this script I have function 'do_get', and if I call this function from the program.lua's CLI, I've got the correct output:

bash $ /usr/bin/lua /path/to/program.lua
Usage: 
  help   - help
  quit   - quit
  do_get - get data
script> do_get
string1
string2
param1
param2

script> _

The question. How I can call function 'do_get' from bash and get the output I need without entering to script's CLI?

The script edit is disallowed.

Thank you

1
  • This isn't really a Lua question, as you're not changing the Lua script. Also, what you're calling isn't a function in the Lua sense. Commented Nov 27, 2020 at 10:54

1 Answer 1

1

You can capture the output by calling the Lua Program in a shell-script and pipe the output to a variable:

lua_output=$(printf "do_get\n\n" | /usr/bin/lua /path/to/program.lua 2>&1)
 
echo $lua_output

If that does not work try a tool that can handle interactive prompts like yes (https://man7.org/linux/man-pages/man1/yes.1.html) yes do_get | /usr/bin/lua /path/to/program.lua or expect (https://man7.org/linux/man-pages/man1/expect.1.html)

Sign up to request clarification or add additional context in comments.

4 Comments

No. I've edited the question and provided more information why I can't launch the script directly from the bash
@AndriiK. ok, i've upodated my answer
@AndriiK. did you try running the example?
@AndriiK. i've updated the answer, you need to handle the interavtive prompt. Try to pipe or a tool like yes or expect, expect will work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.