Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gallery-dl doesn't work with lua subprocess #653

Closed
phanirithvij opened this issue Mar 23, 2020 · 3 comments
Closed

gallery-dl doesn't work with lua subprocess #653

phanirithvij opened this issue Mar 23, 2020 · 3 comments
Labels

Comments

@phanirithvij
Copy link

OS: Windows 10
[gallery-dl][debug] Version 1.13.2
[gallery-dl][debug] Python 3.8.0 - Windows-10-10.0.18362-SP0
[gallery-dl][debug] requests 2.23.0 - urllib3 1.25.6

Gallery-dl.exe is in my PATH.

This call works when called from python

python py.py "https://imgur.com/a/7AtGJJg" 
# file py.py
import sys
import subprocess

result = subprocess.check_output(["gallery-dl", "-g", sys.argv[1]])
print(result.decode('utf8').strip())

Output

https://i.imgur.com/sUWPlCL.png
https://i.imgur.com/MsXOF90.png
https://i.imgur.com/aHFeZJe.png
https://i.imgur.com/HHyTd7i.png
https://i.imgur.com/8B95XmK.png
https://i.imgur.com/3kS88XJ.png
https://i.imgur.com/twleH7a.png
https://i.imgur.com/HlTMB9U.png
https://i.imgur.com/u6uGJsY.png
https://i.imgur.com/9ML4Csl.png
https://i.imgur.com/c8vj8Na.png
https://i.imgur.com/thrIFE5.png
https://i.imgur.com/vgjUCdt.png
https://i.imgur.com/AqWAj4u.png
https://i.imgur.com/04pmPk1.png
https://i.imgur.com/tzigNb7.png
https://i.imgur.com/zDfW42L.png

But when executing it in lua.

url = "https://imgur.com/a/7AtGJJg" 
file = assert(io.popen("gallery-dl -g " .. url, 'r'))
-- file = assert(io.popen("bash -c gallery-dl -g " .. url, 'r'))
output = file:read('*all')
file:close()
print(output)

The error is this

Traceback (most recent call last):
  File "c:\users\rithvij\appdata\local\programs\python\python38\lib\runpy.py", line 192, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\users\rithvij\appdata\local\programs\python\python38\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\Rithvij\AppData\Local\Programs\Python\Python38\Scripts\gallery-dl.exe\__main__.py", line 7, in <module>
  File "c:\users\rithvij\appdata\local\programs\python\python38\lib\site-packages\gallery_dl\__init__.py", line 112, in main
    output.replace_std_streams()
  File "c:\users\rithvij\appdata\local\programs\python\python38\lib\site-packages\gallery_dl\output.py", line 153, in replace_std_streams
    stream.buffer,
AttributeError: 'NoneType' object has no attribute 'buffer'
@mikf
Copy link
Owner

mikf commented Mar 24, 2020

sys.stdout, .stderr, or .stdin can be None when the underlying file descriptors are closed at process start, and I didn't anticipate that. Should be fixed with 4bc161c

@mikf mikf added the bug label Mar 24, 2020
@phanirithvij
Copy link
Author

phanirithvij commented Mar 25, 2020

Please add a test for the subprocess if possible. I don't see how it can be done in python as it worked before this fix. Guess python subprocess module calls the program attached to a shell. But Lua doesn't.

This can be marked as resolved. I was able to call gallery-dl from Lua's subprocess. Thank you.

phanirithvij added a commit to phanirithvij/mpv-config that referenced this issue Mar 25, 2020
@mikf
Copy link
Owner

mikf commented Mar 26, 2020

Guess python subprocess module calls the program attached to a shell. But Lua doesn't.

Running your lua script works just fine on my machine, even with a gallery-dl version before 4bc161c, so there is probably something else going on, but at least it now also works for you.

$ git checkout v1.13.0
$ lua -v
Lua 5.3.5  Copyright (C) 1994-2018 Lua.org, PUC-Rio
$ lua /tmp/script.lua 
https://i.imgur.com/sUWPlCL.png
https://i.imgur.com/MsXOF90.png
https://i.imgur.com/aHFeZJe.png
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants