Yeah calibre uses something very similar, except its implemented in C. But if I understand beowulf's problem, it's that calibre is not creating the correct output file name.
Quote:
Originally Posted by igorsk
Here's a little wrapper I had used to handle unicode commandline arguments.
Code:
import sys, os, ctypes, pprint
class Argvu:
def __init__(self,CommandLine=None):
if CommandLine==None:
CommandLine=ctypes.windll.kernel32.GetCommandLineW()
argv_count=ctypes.c_int()
cmd_string=ctypes.c_wchar_p(CommandLine)
array_memory_address=ctypes.windll.shell32.CommandLineToArgvW(cmd_string,ctypes.byref(argv_count))
match_array_type=ctypes.c_wchar_p*argv_count.value
self.argv=[arg for arg in match_array_type.from_address(array_memory_address)]
#running from a script:
#sys.argv[0] == script.py
#our argv[0] == python.exe
#running from an exe:
#sys.argv[0] == prog.exe
#our argv[0] == prog.exe
#if we have the first case, we need to remove the interpreter from argv
if not sys.argv[0].endswith(".exe") and self.argv[0].endswith(".exe"):
self.argv=self.argv[1:]
ctypes.windll.kernel32.LocalFree(array_memory_address)
def __str__(self):
return pprint.pformat(self.result)
argv = Argvu().argv
if __name__=='__main__':
c2a=Argvu()
print c2a
print c2a.argv
|