From a Python script I want to create a RAR file. I will need to communicate with Rar.exe because I only want the first RAR volume from a multi-volume archive set, nothing more. The -vp
switch makes sure Create next volume ? [Y]es, [N]o, [A]ll
is asked after each volume. The first time this question pops up, I want to answer No. How do I accomplish this?
I've been reading and trying a lot of things and I found out something like this can be accomplished with pexpect. I've been trying the two different Windows ports: wexpect and winpexpect. The result is that my script will hang. No RAR file is created. This is my code:
import wexpect
import sys
rarexe = "C:\Program Files\WinRAR\Rar.exe"
args = ['a', '-vp', '-v2000000b', 'only_first.rar', 'a_big_file.ext']
child = wexpect.spawn(rarexe, args)
child.logfile = sys.stdout
index = child.expect(["Create next volume ? [Y]es, [N]o, [A]ll",
wexpect.EOF, wexpect.TIMEOUT], timeout=10)
if index == 0:
child.sendline("N")
else:
print('error')
Other approaches are welcome too.