code: static String quoteForBatchScript(String arg) {
  
      boolean needsQuotes = false;
      for (int i = 0; i < arg.length(); i++) {
        int c = arg.codePointAt(i);
        if (Character.isWhitespace(c) || c == '"' || c == '=' || c == ',' || c == ';') {
          needsQuotes = true;
          break;
        }
      }
      if (!needsQuotes) {
        return arg;
      }
      StringBuilder quoted = new StringBuilder();
      quoted.append("\"");
      for (int i = 0; i < arg.length(); i++) {
        int cp = arg.codePointAt(i);
        switch (cp) {
        case '"':
          quoted.append('"');
          break;
  
        default:
          break;
        }
        quoted.appendCodePoint(cp);
      }
      if (arg.codePointAt(arg.length() - 1) == '\\') {
        quoted.append("\\");
      }
      quoted.append("\"");
      return quoted.toString();
    }
docs: Quote a command argument for a command to be run by a Windows batch script, if the argument
  needs quoting. Arguments only seem to need quotes in batch scripts if they have certain
  special characters, some of which need extra (and different) escaping.
  
  For example:
  original single argument: ab="cde fgh"
  quoted: "ab^=""cde fgh"""