I’m writing a C app that has an embedded lua script in it. The Lua script takes input from STDIN. So when I’m running the script from the shell it’s like thus:
lua myscript.lua < datafile*
How do I accomplish this from inside the C code?
Thank you.
Use the
dup2(2)system call on descriptor0(stdin) and on the descriptor returned byopen(2)ondatafile:Of course, you need some error-checking in a real-world program.
To implement the behaviour of wildcarding, you may want to look at the
readdir(3)library function.