0

I hava a code in lua produce images and other data containers then these data should be used in another python script.

i tried to use (os.execute(command)) as it shown here https://www.lua.org/pil/22.2.html but i don't know how to pass these parameters direct from lua to python scriprt as arguments

2
  • The same way you pass arguments to anything else, like in the first example in that link that does os.execute("mkdir " .. dirname)? Commented Apr 4, 2018 at 18:10
  • @abarnert that if i want to pass a string like dirname or path so i can concatenate it to command but if my argument not a string like an image or array of elements Commented Apr 8, 2018 at 10:20

1 Answer 1

1

Command-line arguments can only be strings—and only relatively short strings, and only strings which can be handled by your default system encoding.

If you need to pass data that's large, or structured, or just arbitrary binary bytes, you can't use command-line arguments.

The simplest solution is to save the data in a file, then pass the filename as a command-line argument. Then, on the Python side, you just open and read the same file.

You can also stream data into the child process's standard input. Lua doesn't come with anything like Python's subprocess module, but sometimes popen is sufficient.

When popen isn't sufficient, you can build it yourself atop POSIX or Windows API calls. See this answer for an example of doing it for POSIX.

You can also just open a pipe, shared memory segment, etc. for the child to inherit, and then pass a file descriptor or key as a command-line argument.

Finally, you can write a simple socket server (possibly using a higher-level protocol that libraries already exist for ranging from Netstrings over UDP up to HTTP) and pass the port number as a command-line argument.

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

Comments

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.