# Os.execute returning nil

**URL:** https://community.aseprite.org/t/os-execute-returning-nil/22157
**Category:** Bug Reports
**Created:** [May 20, 2024, 5:23am UTC](https://community.aseprite.org/t/os-execute-returning-nil/22157 "2024-05-20T05:23:12Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![DragonDePlatino](https://community.aseprite.org/user_avatar/community.aseprite.org/dragondeplatino/32/18649_2.png) [@DragonDePlatino](https://community.aseprite.org/u/DragonDePlatino)
#### Post date: [May 20, 2024, 5:23am UTC](https://community.aseprite.org/t/os-execute-returning-nil/22157/1 "2024-05-20T05:23:12Z")

</div>

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

```lua
> 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:

```lua
os.execute('7z')
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.

---

<div class="post-metadata">

### Author: ![dacap](https://community.aseprite.org/user_avatar/community.aseprite.org/dacap/32/10_2.png) [@dacap](https://community.aseprite.org/u/dacap)
#### Post date: [May 20, 2024, 9:58pm UTC](https://community.aseprite.org/t/os-execute-returning-nil/22157/2 "2024-05-20T21:58:13Z")

</div>

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](https://github.com/aseprite/aseprite/commit/7172de50075ca31c91a5fdcc98c2c449379e4ee3#diff-993e38baeaf37fe4e0ba7e656f8ae17e1864e347ee352b62b694f09c8a9d0f95R138)

---

<div class="post-metadata">

### Author: ![DragonDePlatino](https://community.aseprite.org/user_avatar/community.aseprite.org/dragondeplatino/32/18649_2.png) [@DragonDePlatino](https://community.aseprite.org/u/DragonDePlatino)
#### Post date: [May 20, 2024, 10:56pm UTC](https://community.aseprite.org/t/os-execute-returning-nil/22157/3 "2024-05-20T22:56:51Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![DragonDePlatino](https://community.aseprite.org/user_avatar/community.aseprite.org/dragondeplatino/32/18649_2.png) [@DragonDePlatino](https://community.aseprite.org/u/DragonDePlatino)
#### Post date: [May 23, 2024, 3:30pm UTC](https://community.aseprite.org/t/os-execute-returning-nil/22157/4 "2024-05-23T15:30:45Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![dacap](https://community.aseprite.org/user_avatar/community.aseprite.org/dacap/32/10_2.png) [@dacap](https://community.aseprite.org/u/dacap)
#### Post date: [May 23, 2024, 5:40pm UTC](https://community.aseprite.org/t/os-execute-returning-nil/22157/5 "2024-05-23T17:40:46Z")

</div>

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

---

<div class="post-metadata">

### Author: ![DragonDePlatino](https://community.aseprite.org/user_avatar/community.aseprite.org/dragondeplatino/32/18649_2.png) [@DragonDePlatino](https://community.aseprite.org/u/DragonDePlatino)
#### Post date: [May 24, 2024, 4:02am UTC](https://community.aseprite.org/t/os-execute-returning-nil/22157/6 "2024-05-24T04:02:59Z")

</div>

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. 👍
