1

I have a Lua script and I want to execute a batch file from within this file; how can I do this?

I've seen examples as follows that I thought could do this but in retrospect I am probably misunderstanding their purpose:

os.execute('C:\\tmp\\MyFile.bat')  

or

local handle = io.open('C:\\tmp\\MyFile.bat')
handle:close()

I believe this question has been asked and answered before: How do I run an executable using Lua?

However my code is failing; I'm not sure why. Is there a library I need to load for 'os' for example?

When I try and run this code I get the following error:

"attempt to index a nil value"

7
  • What about those examples is not working for you? If you are getting errors from either of them please include those. Commented Sep 11, 2014 at 17:51
  • I added it to the post; sorry I left that out. Commented Sep 11, 2014 at 17:55
  • 1
    I assume that's for the second (io.open) case? That just means io.open didn't return a handle, which means something failed. In that case io.open returns a second error value. local handle, err = io.open(...) if not handle then print(err) else handle:close() end`. Commented Sep 11, 2014 at 17:57
  • Also io.open opens the file for reading/writing. It doesn't execute anything. Use os.execute or io.popen for executing processes. Commented Sep 11, 2014 at 18:06
  • I have tried io.popen and os.execute and it's as if io/os are not visible; is there a library I must load? Commented Sep 11, 2014 at 18:12

1 Answer 1

1

You have to use os.execute[[yourFile.bat]] when opening a batch file.
More information for this here

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.