Os.execute returning nil

I am developing an extension that needs to run a local 7z installation to create an archive. In a standalone lua 5.3 console:

> os.execute('7z')
<command output>
true exit 0

> os.execute('7z a')
<command output>
nil exit 7

In my Aseprite v1.3.6 installation running via Steam:

true nil nil

os.execute('7z a')
nil nil nil

And there is no effect on the local filesystem, even if I’m running a valid, hardcoded command like 7z a out.zip *.txt. Is this a security issue with the Steam version? I need the reason and code as well so I can check error codes and display messages to extension users.

Hi @DragonDePlatino, it’s a bug in Aseprite where the overridden os.execute() function returns just one value. The next version v1.3.7 will have a fix for this, calling the original os.execute() after the security dialog when the UI is available: [lua] Use internal variables to store ptrs to original unsecure funct… · aseprite/aseprite@7172de5 · GitHub

1 Like

Good to hear this has already been fixed! I’ll give v1.3.7 a shot and see if that also fixes the command not having any effect on the filesystem.

1 Like

No luck, I wasn’t able to get Aseprite compiling under Windows or my Linux Mint dual-boot. And end users would need to use v.1.3.7 anyways for the script to work. I’ll just need to wait on the next release or release a temporarily cut-down version of the extension.

The v1.3.7 was released this week, was you able to give a try? does it fix the issue?

Yes, I’m now able to get the return values. And with those, I was able to diagnose the problem. For anyone coming here from Google, here are some Windows gotchas:

  1. Try adding & sleep 5 to the end of your command so you can read the output before the console closes. io.popen does not work for getting stdout.
  2. There is a hard limit to how long commands can be. Split up your command into multiple os.execute if it is failing.
  3. If the executable path or one of your arguments contains spaces, you must surround it in ". Additionally, if your command is executed as a child process like:

cmd /k "C:\My Folder\program.exe" -arg "C:\My Folder\file"

Then you must add additional quotation marks, eg.

cmd /k ""C:\My Folder\program.exe" -arg "C:\My Folder\file""

My script does not execute a cmd subshell, but I suspect Aseprite is under the hood because adding the following line to my script fixed the command:

if app.os.windows then command = '"' .. command .. '"' end

Thank you for the new os API btw, I appreciate no longer having to check path separators to do OS checks now. :+1: