prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  `cli.python_api` captures `stdout` from `cli.common.confirm_yn`
  `cli.python_api.run_command` captures any output to `stdout`/`stderr` via `common.io.captured`. This causes the user confirmation messages from `cli.common.confirm_yn`, i.e.,
  ```bash
  Proceed ([y]/n)? 
  ```
  to also be captured, i.e., not being output/accessible until the command finishes (which might be never if the user does not interact). The examples in the doc string are
  ```python
      Examples:
          >>  run_command(Commands.CREATE, "-n newenv python=3 flask", use_exception_handler=True)
          >>  run_command(Commands.CREATE, "-n newenv", "python=3", "flask")
          >>  run_command(Commands.CREATE, ["-n newenv", "python=3", "flask"], search_path=())
  ```
  and show exactly such use cases.
  
  Due to this, `run_command` is only generally usable if any of `--json`, `--yes` or `--dry-run` is supplied.
  There could be two solutions to this:
    1. Force the user to include at least one of those arguments.
    2. Instead of only capturing the output, it could be recorded but also forwarded to `stdout`/`stderr`. This could/should be made optional via some `kwarg` for `run_command`.
  
  Possibility 1. is of course much simpler and could at least serve as a temporary solution.
  `cli.python_api` captures `stdout` from `cli.common.confirm_yn`
  `cli.python_api.run_command` captures any output to `stdout`/`stderr` via `common.io.captured`. This causes the user confirmation messages from `cli.common.confirm_yn`, i.e.,
  ```bash
  Proceed ([y]/n)? 
  ```
  to also be captured, i.e., not being output/accessible until the command finishes (which might be never if the user does not interact). The examples in the doc string are
  ```python
      Examples:
          >>  run_command(Commands.CREATE, "-n newenv python=3 flask", use_exception_handler=True)
          >>  run_command(Commands.CREATE, "-n newenv", "python=3", "flask")
          >>  run_command(Commands.CREATE, ["-n newenv", "python=3", "flask"], search_path=())
  ```
  and show exactly such use cases.
  
  Due to this, `run_command` is only generally usable if any of `--json`, `--yes` or `--dry-run` is supplied.
  There could be two solutions to this:
    1. Force the user to include at least one of those arguments.
    2. Instead of only capturing the output, it could be recorded but also forwarded to `stdout`/`stderr`. This could/should be made optional via some `kwarg` for `run_command`.
  
  Possibility 1. is of course much simpler and could at least serve as a temporary solution.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `conda/cli/python_api.py`
  Content:
  ```
  1 # -*- coding: utf-8 -*-
  2 from __future__ import absolute_import, division, print_function, unicode_literals
  3 
  4 from importlib import import_module
  5 from logging import getLogger
  6 from shlex import split
  7 
  8 from ..base.constants import APP_NAME, SEARCH_PATH
  9 from ..base.context import context
  10 from ..cli.main import generate_parser
  11 from ..common.io import captured, replace_log_streams
  12 from ..common.path import win_path_double_escape
  13 from ..exceptions import conda_exception_handler
  14 from ..gateways import initialize_logging
  15 
  16 initialize_logging()
  17 log = getLogger(__name__)
  18 
  19 
  20 class Commands:
  21     CONFIG = "config"
  22     CLEAN = "clean"
  23     CREATE = "create"
  24     INFO = "info"
  25     INSTALL = "install"
  26     LIST = "list"
  27     REMOVE = "remove"
  28     SEARCH = "search"
  29     UPDATE = "update"
  30 
  31 
  32 def get_configure_parser_function(command):
  33     module = 'conda.cli.main_' + command
  34     return import_module(module).configure_parser
  35 
  36 
  37 def run_command(command, *arguments, **kwargs):
  38     """
  39 
  40     Args:
  41         command: one of the Commands.X
  42         *arguments: instructions you would normally pass to the conda comamnd on the command line
  43                     see below for examples
  44         **kwargs: special instructions for programmatic overrides
  45           use_exception_handler: defaults to False.  False will let the code calling
  46               `run_command` handle all exceptions.  True won't raise when an exception
  47               has occured, and instead give a non-zero return code
  48           search_path: an optional non-standard search path for configuration information
  49               that overrides the default SEARCH_PATH
  50 
  51     Returns: a tuple of stdout, stderr, and return_code
  52 
  53     Examples:
  54         >>  run_command(Commands.CREATE, "-n newenv python=3 flask", use_exception_handler=True)
  55         >>  run_command(Commands.CREATE, "-n newenv", "python=3", "flask")
  56         >>  run_command(Commands.CREATE, ["-n newenv", "python=3", "flask"], search_path=())
  57 
  58 
  59     """
  60     use_exception_handler = kwargs.get('use_exception_handler', False)
  61     configuration_search_path = kwargs.get('search_path', SEARCH_PATH)
  62     p, sub_parsers = generate_parser()
  63     get_configure_parser_function(command)(sub_parsers)
  64 
  65     arguments = map(win_path_double_escape, arguments)
  66     command_line = "%s %s" % (command, " ".join(arguments))
  67     split_command_line = split(command_line)
  68 
  69     args = p.parse_args(split_command_line)
  70     context.__init__(
  71         search_path=configuration_search_path,
  72         app_name=APP_NAME,
  73         argparse_args=args,
  74     )
  75     log.debug("executing command >>>  conda %s", command_line)
  76     try:
  77         with captured() as c, replace_log_streams():
  78             if use_exception_handler:
  79                 return_code = conda_exception_handler(args.func, args, p)
  80             else:
  81                 return_code = args.func(args, p)
  82     except Exception as e:
  83         log.debug("\n  stdout: %s\n  stderr: %s", c.stdout, c.stderr)
  84         e.stdout, e.stderr = c.stdout, c.stderr
  85         raise e
  86     log.debug("\n  stdout: %s\n  stderr: %s\n  return_code: %s", c.stdout, c.stderr, return_code)
  87     return c.stdout, c.stderr, return_code
  88
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/conda/cli/python_api.py b/conda/cli/python_api.py
  --- a/conda/cli/python_api.py
  +++ b/conda/cli/python_api.py
  @@ -35,7 +35,10 @@
   
   
   def run_command(command, *arguments, **kwargs):
  -    """
  +    """Runs a conda command in-process with a given set of command-line interface arguments.
  +
  +    Differences from the command-line interface:
  +        Always uses --yes flag, thus does not ask for confirmation.
   
       Args:
           command: one of the Commands.X
  @@ -67,6 +70,7 @@
       split_command_line = split(command_line)
   
       args = p.parse_args(split_command_line)
  +    args.yes = True  # always skip user confirmation, force setting context.always_yes
       context.__init__(
           search_path=configuration_search_path,
           app_name=APP_NAME,
  
verification_info: {"golden_diff": "diff --git a/conda/cli/python_api.py b/conda/cli/python_api.py\n--- a/conda/cli/python_api.py\n+++ b/conda/cli/python_api.py\n@@ -35,7 +35,10 @@\n \n \n def run_command(command, *arguments, **kwargs):\n-    \"\"\"\n+    \"\"\"Runs a conda command in-process with a given set of command-line interface arguments.\n+\n+    Differences from the command-line interface:\n+        Always uses --yes flag, thus does not ask for confirmation.\n \n     Args:\n         command: one of the Commands.X\n@@ -67,6 +70,7 @@\n     split_command_line = split(command_line)\n \n     args = p.parse_args(split_command_line)\n+    args.yes = True  # always skip user confirmation, force setting context.always_yes\n     context.__init__(\n         search_path=configuration_search_path,\n         app_name=APP_NAME,\n", "issue": "`cli.python_api` captures `stdout` from `cli.common.confirm_yn`\n`cli.python_api.run_command` captures any output to `stdout`/`stderr` via `common.io.captured`. This causes the user confirmation messages from `cli.common.confirm_yn`, i.e.,\r\n```bash\r\nProceed ([y]/n)? \r\n```\r\nto also be captured, i.e., not being output/accessible until the command finishes (which might be never if the user does not interact). The examples in the doc string are\r\n```python\r\n    Examples:\r\n        >>  run_command(Commands.CREATE, \"-n newenv python=3 flask\", use_exception_handler=True)\r\n        >>  run_command(Commands.CREATE, \"-n newenv\", \"python=3\", \"flask\")\r\n        >>  run_command(Commands.CREATE, [\"-n newenv\", \"python=3\", \"flask\"], search_path=())\r\n```\r\nand show exactly such use cases.\r\n\r\nDue to this, `run_command` is only generally usable if any of `--json`, `--yes` or `--dry-run` is supplied.\r\nThere could be two solutions to this:\r\n  1. Force the user to include at least one of those arguments.\r\n  2. Instead of only capturing the output, it could be recorded but also forwarded to `stdout`/`stderr`. This could/should be made optional via some `kwarg` for `run_command`.\r\n\r\nPossibility 1. is of course much simpler and could at least serve as a temporary solution.\n`cli.python_api` captures `stdout` from `cli.common.confirm_yn`\n`cli.python_api.run_command` captures any output to `stdout`/`stderr` via `common.io.captured`. This causes the user confirmation messages from `cli.common.confirm_yn`, i.e.,\r\n```bash\r\nProceed ([y]/n)? \r\n```\r\nto also be captured, i.e., not being output/accessible until the command finishes (which might be never if the user does not interact). The examples in the doc string are\r\n```python\r\n    Examples:\r\n        >>  run_command(Commands.CREATE, \"-n newenv python=3 flask\", use_exception_handler=True)\r\n        >>  run_command(Commands.CREATE, \"-n newenv\", \"python=3\", \"flask\")\r\n        >>  run_command(Commands.CREATE, [\"-n newenv\", \"python=3\", \"flask\"], search_path=())\r\n```\r\nand show exactly such use cases.\r\n\r\nDue to this, `run_command` is only generally usable if any of `--json`, `--yes` or `--dry-run` is supplied.\r\nThere could be two solutions to this:\r\n  1. Force the user to include at least one of those arguments.\r\n  2. Instead of only capturing the output, it could be recorded but also forwarded to `stdout`/`stderr`. This could/should be made optional via some `kwarg` for `run_command`.\r\n\r\nPossibility 1. is of course much simpler and could at least serve as a temporary solution.\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\nfrom __future__ import absolute_import, division, print_function, unicode_literals\n\nfrom importlib import import_module\nfrom logging import getLogger\nfrom shlex import split\n\nfrom ..base.constants import APP_NAME, SEARCH_PATH\nfrom ..base.context import context\nfrom ..cli.main import generate_parser\nfrom ..common.io import captured, replace_log_streams\nfrom ..common.path import win_path_double_escape\nfrom ..exceptions import conda_exception_handler\nfrom ..gateways import initialize_logging\n\ninitialize_logging()\nlog = getLogger(__name__)\n\n\nclass Commands:\n    CONFIG = \"config\"\n    CLEAN = \"clean\"\n    CREATE = \"create\"\n    INFO = \"info\"\n    INSTALL = \"install\"\n    LIST = \"list\"\n    REMOVE = \"remove\"\n    SEARCH = \"search\"\n    UPDATE = \"update\"\n\n\ndef get_configure_parser_function(command):\n    module = 'conda.cli.main_' + command\n    return import_module(module).configure_parser\n\n\ndef run_command(command, *arguments, **kwargs):\n    \"\"\"\n\n    Args:\n        command: one of the Commands.X\n        *arguments: instructions you would normally pass to the conda comamnd on the command line\n                    see below for examples\n        **kwargs: special instructions for programmatic overrides\n          use_exception_handler: defaults to False.  False will let the code calling\n              `run_command` handle all exceptions.  True won't raise when an exception\n              has occured, and instead give a non-zero return code\n          search_path: an optional non-standard search path for configuration information\n              that overrides the default SEARCH_PATH\n\n    Returns: a tuple of stdout, stderr, and return_code\n\n    Examples:\n        >>  run_command(Commands.CREATE, \"-n newenv python=3 flask\", use_exception_handler=True)\n        >>  run_command(Commands.CREATE, \"-n newenv\", \"python=3\", \"flask\")\n        >>  run_command(Commands.CREATE, [\"-n newenv\", \"python=3\", \"flask\"], search_path=())\n\n\n    \"\"\"\n    use_exception_handler = kwargs.get('use_exception_handler', False)\n    configuration_search_path = kwargs.get('search_path', SEARCH_PATH)\n    p, sub_parsers = generate_parser()\n    get_configure_parser_function(command)(sub_parsers)\n\n    arguments = map(win_path_double_escape, arguments)\n    command_line = \"%s %s\" % (command, \" \".join(arguments))\n    split_command_line = split(command_line)\n\n    args = p.parse_args(split_command_line)\n    context.__init__(\n        search_path=configuration_search_path,\n        app_name=APP_NAME,\n        argparse_args=args,\n    )\n    log.debug(\"executing command >>>  conda %s\", command_line)\n    try:\n        with captured() as c, replace_log_streams():\n            if use_exception_handler:\n                return_code = conda_exception_handler(args.func, args, p)\n            else:\n                return_code = args.func(args, p)\n    except Exception as e:\n        log.debug(\"\\n  stdout: %s\\n  stderr: %s\", c.stdout, c.stderr)\n        e.stdout, e.stderr = c.stdout, c.stderr\n        raise e\n    log.debug(\"\\n  stdout: %s\\n  stderr: %s\\n  return_code: %s\", c.stdout, c.stderr, return_code)\n    return c.stdout, c.stderr, return_code\n", "path": "conda/cli/python_api.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\nfrom __future__ import absolute_import, division, print_function, unicode_literals\n\nfrom importlib import import_module\nfrom logging import getLogger\nfrom shlex import split\n\nfrom ..base.constants import APP_NAME, SEARCH_PATH\nfrom ..base.context import context\nfrom ..cli.main import generate_parser\nfrom ..common.io import captured, replace_log_streams\nfrom ..common.path import win_path_double_escape\nfrom ..exceptions import conda_exception_handler\nfrom ..gateways import initialize_logging\n\ninitialize_logging()\nlog = getLogger(__name__)\n\n\nclass Commands:\n    CONFIG = \"config\"\n    CLEAN = \"clean\"\n    CREATE = \"create\"\n    INFO = \"info\"\n    INSTALL = \"install\"\n    LIST = \"list\"\n    REMOVE = \"remove\"\n    SEARCH = \"search\"\n    UPDATE = \"update\"\n\n\ndef get_configure_parser_function(command):\n    module = 'conda.cli.main_' + command\n    return import_module(module).configure_parser\n\n\ndef run_command(command, *arguments, **kwargs):\n    \"\"\"Runs a conda command in-process with a given set of command-line interface arguments.\n\n    Differences from the command-line interface:\n        Always uses --yes flag, thus does not ask for confirmation.\n\n    Args:\n        command: one of the Commands.X\n        *arguments: instructions you would normally pass to the conda comamnd on the command line\n                    see below for examples\n        **kwargs: special instructions for programmatic overrides\n          use_exception_handler: defaults to False.  False will let the code calling\n              `run_command` handle all exceptions.  True won't raise when an exception\n              has occured, and instead give a non-zero return code\n          search_path: an optional non-standard search path for configuration information\n              that overrides the default SEARCH_PATH\n\n    Returns: a tuple of stdout, stderr, and return_code\n\n    Examples:\n        >>  run_command(Commands.CREATE, \"-n newenv python=3 flask\", use_exception_handler=True)\n        >>  run_command(Commands.CREATE, \"-n newenv\", \"python=3\", \"flask\")\n        >>  run_command(Commands.CREATE, [\"-n newenv\", \"python=3\", \"flask\"], search_path=())\n\n\n    \"\"\"\n    use_exception_handler = kwargs.get('use_exception_handler', False)\n    configuration_search_path = kwargs.get('search_path', SEARCH_PATH)\n    p, sub_parsers = generate_parser()\n    get_configure_parser_function(command)(sub_parsers)\n\n    arguments = map(win_path_double_escape, arguments)\n    command_line = \"%s %s\" % (command, \" \".join(arguments))\n    split_command_line = split(command_line)\n\n    args = p.parse_args(split_command_line)\n    args.yes = True  # always skip user confirmation, force setting context.always_yes\n    context.__init__(\n        search_path=configuration_search_path,\n        app_name=APP_NAME,\n        argparse_args=args,\n    )\n    log.debug(\"executing command >>>  conda %s\", command_line)\n    try:\n        with captured() as c, replace_log_streams():\n            if use_exception_handler:\n                return_code = conda_exception_handler(args.func, args, p)\n            else:\n                return_code = args.func(args, p)\n    except Exception as e:\n        log.debug(\"\\n  stdout: %s\\n  stderr: %s\", c.stdout, c.stderr)\n        e.stdout, e.stderr = c.stdout, c.stderr\n        raise e\n    log.debug(\"\\n  stdout: %s\\n  stderr: %s\\n  return_code: %s\", c.stdout, c.stderr, return_code)\n    return c.stdout, c.stderr, return_code\n", "path": "conda/cli/python_api.py"}]}