**Kibana version:**  8.3 Snapshot Kibana self-managed environment

**Host OS and Browser version:** Windows, All

**Build details:**
```
VERSION: 8.3.0 Snapshot self-managed
BUILD: 52512
COMMIT: df225b213b188c81888141cee2ec191424fc0649
Elasticsearch artifact link: https://snapshots.elastic.co/8.3.0-6ba9f710/downloads/elasticsearch/elasticsearch-8.3.0-SNAPSHOT-windows-x86_64.zip
```

**Preconditions:**
1. 8.3 Snapshot Kibana self-managed environment should be available.

**Steps to reproduce:**
1. Navigate to `C:\elk\elasticsearch\bin>` through cmd.
2. Run below command:
`elasticsearch-certutil ca --pem`
3. Observe Java exceptions on running cert creation command.

**Expected Result:**
 CA cert should be created on running `elasticsearch-certutil ca --pem` command.

**Screenshot:**
![1](https://user-images.githubusercontent.com/77374876/167078819-20c28e8e-5886-443f-8ab7-1e58d80fb1e2.JPG)


distribution/tools/cli-launcher/src/main/java/org/elasticsearch/launcher/CliToolLauncher.java
Terminal terminal = Terminal.DEFAULT;
        Runtime.getRuntime().addShutdownHook(createShutdownHook(terminal, command));
        int exitCode = command.main(args, terminal, pinfo);
        terminal.flush(); 
        if (exitCode != ExitCodes.OK) {
            exit(exitCode);
        }
    }
    
    static String getToolName(Map<String, String> sysprops) {
        String toolname = sysprops.getOrDefault("cli.name", "");
        if (toolname.isBlank()) {
            String script = sysprops.get("cli.script");
            int nameStart = script.lastIndexOf(SCRIPT_PREFIX) + SCRIPT_PREFIX.length();
            toolname = script.substring(nameStart);
            if (sysprops.get("os.name").startsWith("Windows")) {
                int dotIndex = toolname.indexOf(".bat"); 
                toolname = toolname.substring(0, dotIndex);
            }
        }
        return toolname;
    }
    static Thread createShutdownHook(Terminal terminal, Closeable closeable) {
        return new Thread(() -> {
            try {
                closeable.close();
            } catch (final IOException e) {
                e.printStackTrace(terminal.getErrorWriter());
            }
            terminal.flush();