Unrar not found (subprocess.Popen())

Hello,

I’m developing an addon for my personal usage and I need to extract a rar archive via this script.
So I’ve installed unrar on CE (via ENTWARE package).

I connect via SSH and verified that unrar is well installed and is working fine.

Now, back in my script, I’m calling unrar via subprocess.call():
result = subprocess.Popen(“unrar e /source/to/my/rar/archive.rar /my/target/dir/”, shell=True, stdout=subprocess.PIPE).stdout.read()
log(sys._getframe().f_code.co_name, result)

but nothing happened and result is empty.
So I verify if unrar command exist by doing:
result = subprocess.Popen(“type unrar”, shell=True, stdout=subprocess.PIPE).stdout.read()
log(sys._getframe().f_code.co_name, result)
And this type, result return: unrar: not found

What should I do to unrar my archive ?

Thank you

In ssh session type

which unrar

and use absolute path in python. Or set extra PATH.

so I found the solution:
result = subprocess.Popen(“/opt/bin/unrar e /source/to/my/rar/archive.rar /my/target/dir/”, shell=True, stdout=subprocess.PIPE).stdout.read()

But now I’m facing another issue:
My rar file contains files with non ASCII characters and when using unrar in subprocess.Popen() fails as these characters are not properly recognized.
For example, the rar archive contains a file:
xxxx.简体.srt
When I try to extract it, i got:
xxxx.??.srt
Program aborted

(I have no problem extracting the file via ssh => non ASCII characters are well recognized)

Any idea ?
Thank you

Try to disable messages

/opt/bin/unrar e -idq /source/to/my/rar/archive.rar /my/target/dir/

does not work :confused:

Can you make me small rar file to test with? And upload it to somewhere.

sure, please find attached here:
test_file.rar (245.3 KB)
Thank you

Sadly I can’t extract it even in SSH console directly.

I’m not a python guru, but maybe proper encoding setting in script could help.

Edit: try this

Thanks, I will investigate, it’s surely an encoding/decoding issue.

When i run locale via ssh, everything is set to UTF-8 (which is good), but when i run the same command in subprocess, everything is POSIX, which is may the root cause. So I need to figure out how to run subprocess in UTF-8…

I need to install Locale addon to get UTF-8 support.
Then I installed System-tools addon which includes newer unrar program than entware.
And with unrar from addon I could unpacked provided sample file.

How do you run Python script? I run it in ssh and there it works.

which version is your unrar ? mine is 5.61
I have no issue extracting my file via ssh. It’s really when i run unrar cmb in subprocress.call() in python.
The python script is actually a kodi subtitle addon i’m writting for myself. So the script is called via kodi interface (video OSD).

Same unrar 5.61.
For me unrar extracts sample file from kodi too using

kodi-send --action=“RunScript(/storage/downloads/python/a.py)”

with

result = subprocess.Popen(“unrar x -o+ /storage/downloads/python/subtitles.rar /storage/downloads/python/unpacked/”, shell=True, stdout=subprocess.PIPE).stdout.read()

Did you installed Locale addon? And which CE version you are using?

opkg install locale returns Unknown package ‘locale’.
I’m using CE 9.0.1

You don’t need entware packages for this.
Unrar is in CoreELEC System-tools addon and locales are in Locale addon. After reboot your python script should unpack .rar file successfully.

1 Like

ah yes, it’s working after installing these 2 kodi addons: system-tools and locale
Big THANK YOU for your help !!
非常感谢 :slight_smile:

1 Like

Excellent!

I assume Python in CE doesn’t have rar archive support to directly unpack archives without calling external program.

you mean vfs.libarchive addon in order to use archive:// ?
I tried it, but could never make it work