Server IP : 85.214.239.14 / Your IP : 18.116.85.96 Web Server : Apache/2.4.62 (Debian) System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.18 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /proc/self/root/proc/2/cwd/proc/self/root/lib/python3/dist-packages/ansible/plugins/shell/ |
Upload File : |
# Copyright (c) 2019 Ansible Project # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import (absolute_import, division, print_function) __metaclass__ = type DOCUMENTATION = ''' name: cmd version_added: '2.8' short_description: Windows Command Prompt description: - Used with the 'ssh' connection plugin and no C(DefaultShell) has been set on the Windows host. extends_documentation_fragment: - shell_windows ''' import re from ansible.plugins.shell.powershell import ShellModule as PSShellModule # these are the metachars that have a special meaning in cmd that we want to escape when quoting _find_unsafe = re.compile(r'[\s\(\)\%\!^\"\<\>\&\|]').search class ShellModule(PSShellModule): # Common shell filenames that this plugin handles COMPATIBLE_SHELLS = frozenset() # type: frozenset[str] # Family of shells this has. Must match the filename without extension SHELL_FAMILY = 'cmd' _SHELL_REDIRECT_ALLNULL = '>nul 2>&1' _SHELL_AND = '&&' # Used by various parts of Ansible to do Windows specific changes _IS_WINDOWS = True def quote(self, s): # cmd does not support single quotes that the shlex_quote uses. We need to override the quoting behaviour to # better match cmd.exe. # https://blogs.msdn.microsoft.com/twistylittlepassagesallalike/2011/04/23/everyone-quotes-command-line-arguments-the-wrong-way/ # Return an empty argument if not s: return '""' if _find_unsafe(s) is None: return s # Escape the metachars as we are quoting the string to stop cmd from interpreting that metachar. For example # 'file &whoami.exe' would result in 'file $(whoami.exe)' instead of the literal string # https://stackoverflow.com/questions/3411771/multiple-character-replace-with-python for c in '^()%!"<>&|': # '^' must be the first char that we scan and replace if c in s: # I can't find any docs that explicitly say this but to escape ", it needs to be prefixed with \^. s = s.replace(c, ("\\^" if c == '"' else "^") + c) return '^"' + s + '^"'