免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2648 | 回复: 8
打印 上一主题 下一主题

win下把perl 编译成exe,如何同时打包原代码中需要读入的一个文本 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-03-30 08:51 |只看该作者 |倒序浏览
perl 编译成exe,如何加载原代码中需要读入的一个文本???

我的意思是
源代码中 有一个 hash 表
它的内容是从当前目录的一个txt文本中读入的

现在把这个代码编译成exe 去执行
如何让exe不需要再去寻找 加载 那个txt文本
而是在编译的时候一块打包进去

谢谢
求教了

论坛徽章:
0
2 [报告]
发表于 2012-03-30 09:14 |只看该作者
那就将txt文本里面的东西写入代码中的变量

论坛徽章:
0
3 [报告]
发表于 2012-03-30 09:22 |只看该作者
想了半天
也只能像2楼所说
直接 把文本内容 写到 程序中

我前面想多了,觉得这样一来代码好长,以为有别的解决方法呢
谢了

论坛徽章:
0
4 [报告]
发表于 2012-03-30 09:25 |只看该作者
sncchen 发表于 2012-03-30 09:22
想了半天
也只能像2楼所说
直接 把文本内容 写到 程序中

带着那个txt会怎么样呢- -

论坛徽章:
0
5 [报告]
发表于 2012-03-30 10:43 |只看该作者
回复 4# kk861123


    perl 代码中的一个 hash 是从当前目录的txt读入的
生成的exe  如果不和txt放在一块 运行 就会执行失败   

论坛徽章:
0
6 [报告]
发表于 2012-04-01 07:02 |只看该作者
本帖最后由 iamlimeng 于 2012-04-01 08:35 编辑

有办法的,PDK打包时,允许额外绑定程序运行所需资源,比如Icon、数据,在PerlApp的Fils标签,Bound files中设置中。

论坛徽章:
0
7 [报告]
发表于 2012-04-01 08:43 |只看该作者
回复 6# iamlimeng
这个bind  选项我也注意到了

    --bind file
         List an additional file to include in the application. The
         application can access this file at runtime through the
         "PerlApp::get_bound_file()" and "PerlApp::extract_bound_file()"
         functions. Separate multiple filenames with semicolons. This option
         can be repeated.

         Additional options can be specified after the filename, within
         brackets and separated by commas:

            name[option1,option2,...]

         Valid options are:

         file=filename
             Specifies the filesystem name of the file to be bound. Cannot
             be specified together with "data". If neither "file" nor "data"
             is specified, then the bound "name" is used as the filesystem
             name as well.

         data=*text*
             File contents specified as literal text. Cannot be specified
             together with "file".

         text
             The file will be read in text mode on Windows.

         extract
             The bound file is extracted into the "TEMP" directory upon
             application start. It is deleted when the application
             terminates. The extraction directory is added to the "PATH"
             environment variable (as well as to the "LD_LIBRARY_PATH"
             variable on Unix). It is also added to the front of @INC.

         mode=*file permissions*
             Specifies the access mode for the file when extracted either by
             the "extract" option or the "PerlApp::extract_bound_file()"
             function. File permissions must be specified as an octal number
             (0555 by default); "PerlApp" implicitly calls chmod() after
             extracting the file to make sure it ends up with the right
             permission bits. The "mode=" prefix is optional.

         Examples:

             --bind PerlEz.dll[file=\perl\bin\PerlEz.dll,extract]
             --bind data.txt[text,0777]

         Note: Files bound using the "extract" suboption of "--bind" or
         extracted via "PerlApp::extract_bound_file()" are written to a a
         per-process temporary directory and are automatically deleted when
         the process ends. This occurs regardless of whether the "--clean"
         option is used.

我想的也是 bind 一下就可以了
但试了几次都失败,以为是自己对上文理解错了
有机会再好好研究一下吧
谢谢你的回复

论坛徽章:
0
8 [报告]
发表于 2012-04-01 08:50 |只看该作者
失败的原因是:未允许启动程序时自动释放绑定的文件。将Automatic at startup选项选定,这样,程序运行时,会将绑定的文件临时释放到程序的临时文件夹,以供程序调用。

但这样做的风险是会泄漏数据,如果你的数据不希望共享给其他人,还是内嵌在程序中比较安全。

论坛徽章:
0
9 [报告]
发表于 2012-04-01 08:58 |只看该作者
iamlimeng 发表于 2012-04-01 08:50
失败的原因是:未允许启动程序时自动释放绑定的文件。将Automatic at startup选项选定,这样,程序运行时, ...


学习了
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP