Fastlane导出FL_CHANGELOG到文件失败求助:特殊字符长字符串写入问题
解决Fastlane写入带特殊字符变更日志到文件的问题
优先用Ruby原生文件操作,彻底避开shell转义问题:
在你的Fastlane lane里直接添加Ruby代码,无需调用shell命令:changelog_content = lane_context[SharedValues::FL_CHANGELOG] File.write("my_doc.txt", changelog_content)Ruby的
File.write会完整保留原始字符串的换行、双引号等特殊字符,不需要额外处理。若必须用shell命令(不推荐),通过Ruby的Shellwords转义后再执行:
changelog_content = lane_context[SharedValues::FL_CHANGELOG] escaped_content = Shellwords.escape(changelog_content) sh "printf '%s' #{escaped_content} > my_doc.txt"Shellwords.escape会自动把所有特殊字符转成shell能正确解析的格式,避免语法错误。
示例待写入的变更日志内容:
JIRA-Ticket, some text, fixed pop-up crash JIRA-1, JIRA-22 fixed empty SendingMethod screen some string with ", and other chars added UILabel+Utils, title case.
内容的提问来源于stack exchange,提问作者Constantin Saulenco
相关产品推荐
相关产品推荐

