Split a command line's arguments in a shell-like manner. This is a special version for windows that use a ctypes call to CommandLineToArgvW to do the argv splitting. The posix parameter is ignored. If strict=False, process_common.arg_split(...strict=False) is used i
(commandline, posix=False, strict=True)
| 177 | LocalFree.arg_types = [HLOCAL] |
| 178 | |
| 179 | def arg_split(commandline, posix=False, strict=True): |
| 180 | """Split a command line's arguments in a shell-like manner. |
| 181 | |
| 182 | This is a special version for windows that use a ctypes call to CommandLineToArgvW |
| 183 | to do the argv splitting. The posix parameter is ignored. |
| 184 | |
| 185 | If strict=False, process_common.arg_split(...strict=False) is used instead. |
| 186 | """ |
| 187 | #CommandLineToArgvW returns path to executable if called with empty string. |
| 188 | if commandline.strip() == "": |
| 189 | return [] |
| 190 | if not strict: |
| 191 | # not really a cl-arg, fallback on _process_common |
| 192 | return py_arg_split(commandline, posix=posix, strict=strict) |
| 193 | argvn = c_int() |
| 194 | result_pointer = CommandLineToArgvW(py3compat.cast_unicode(commandline.lstrip()), ctypes.byref(argvn)) |
| 195 | result_array_type = LPCWSTR * argvn.value |
| 196 | result = [arg for arg in result_array_type.from_address(ctypes.addressof(result_pointer.contents))] |
| 197 | retval = LocalFree(result_pointer) |
| 198 | return result |
| 199 | except AttributeError: |
| 200 | arg_split = py_arg_split |
| 201 |
no outgoing calls