1

I'm trying to use os.execute(), but I'm getting this problem:

attempt to call field 'execute' (a nil value)

I've done os = require 'os' but when I do: os.execute("mkdir" .. var) it's giving me the above error.

From what I've worked out, it's because it's not calling in all of the stuff from os, but I've looked and I can't figure out how to call in everything from os. In python i'd do from os import * but I don't know the code for lua. I've tried using package.loadlib('os', 'execute') but that didn't work. :/

EDIT: I did a separate test with love2D, and it worked. so I can't see why this isn't working...

4
  • are you sure you don't have code somewhere that is overwritting/reassigning the os.execute function in the problem script? do you have any local table objects named os? Commented Feb 22, 2013 at 16:19
  • ohhh right! I've got os = "NT"/"unix". That explains why it's not working :D. Thank you! I'll rename the variable now :) EDIT: You ought to add that as an answer. Commented Feb 22, 2013 at 16:22
  • How do I close the topic? Commented Feb 22, 2013 at 16:27
  • there should be a delete option under your post if you wish to delete the question Commented Feb 22, 2013 at 16:39

2 Answers 2

2

are you sure you don't have code somewhere that is overwritting/reassigning the os.execute function in the problem script? do you have any local table objects named os?

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

2 Comments

Thanks, this helps. I've renamed my os variable to host :3
ahhh, the beauty of dynamic languages letting you clobber built-in libraries :P
0

try this:

require 'os';
if package.loaded['os'] and type(package.loaded['os']) == "table" then
  local os = package.loaded['os'];
  --from here use the local os variable to call anything inside os.
  --main block of code
end

I hope this works for you.

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.