D
D
DS2022-03-29 12:20:54
Python
DS, 2022-03-29 12:20:54

Archiving rar via python doesn't work but works via cmd, what should I do?

import os
import sys

my_loc, me = os.path.split(sys.argv[0])
print(my_loc)
target = "C:\\Users\\Cat Kingdom\\Desktop\\Scripts"
rarloc = f'C: \\Users\\Cat Kingdom\\Desktop\\{me}.rar'
command=f'"c:\\program files\\winrar\\rar.exe" a "{rarloc}" "{target}"'

task = os.system(command)
if not task:
print('Success')
else :print(task)
# output = 1

'''
command = '"c:\\program files\\winrar\\rar.exe" a "C:\\Users\\Cat Kingdom\\Desktop\\counter.py.rar" "C:\\Users\\Cat Kingdom\\Desktop\\Scripts"'
If in cmd type "c:\\program files\\winrar\\rar.exe" a "C:\\Users\\Cat Kingdom\\Desktop\\counter.py.rar" "C:\\Users\\ Cat Kingdom\\Desktop\\Scripts" then works fine
Question - why doesn't it work through python? '''

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2022-03-29
@Vindicar

The path contains Cyrillic. Possibly an encoding problem. Check on the path only with Latin, for starters, and make sure that you have the encoding specified at the beginning of the script file.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question