首页 > 解决方案 > Java 运行时没有正确格式化 python args

问题描述

private static void sendEmailGeneric(String titleMessage, String textMessage, String email, String subject, List<HashMap<String, String>> attachmentPaths) {
        /*F
         * Attachment tiene la siguiente estructura:
         * List -> HashMap({ file_path: string, file_title: string })
         * */
        ArrayList<String> attachmentList = new ArrayList<>();
        for (HashMap<String, String> attachmentPath : attachmentPaths) {
            attachmentList.add(attachmentPath.get("file_title").concat(":").concat(attachmentPath.get("file_path")));
        }
        LOGGER.info("Adjuntando ".concat(attachmentList.toString()));
        String mailerPath = new File("/opt/sintesis/api/mailer/mailer.py").getAbsolutePath();
        String[] builder = {"python3",
                mailerPath,
                "\"".concat(email).concat("\""),
                "\"".concat(subject).concat("\""),
                "\"".concat(titleMessage).concat("\""),
                "\"".concat(textMessage).concat("\""),
                "\"".concat(attachmentList.toString().replace("[", "").replace("]", "")).concat("\"")};
        try {
            Runtime.getRuntime().exec(builder);
            LOGGER.info("Ejecutando mailer ".concat(builder.toString()));
        } catch (Exception e) {
            LOGGER.error(e.getMessage());
            LOGGER.error("Ha sucedido un error al enviar el correo a ".concat(email).concat(", con asunto: ").concat(subject));
        }
    }

我有这个调用python脚本的代码,问题是参数没有正确显示

python3 mailer.py mymail@mail.com "This is a test" "Subuject" "Message" "index:index.html,dna.pdf"

“字符没有在java中格式化并且正在删除的地方。所以我做错了什么,因为我尝试了很多东西但没有任何效果。

发送消息时,邮件中的标题消息像这样显示“这个 标题是消息

所以我猜问题出在java解析器或类似的东西上。

标签: javapythonspring-boot

解决方案


推荐阅读