perl怎么拷贝文件,连属性一起拷贝

边城狂人 2009-03-30 03:42:35
我在Linux下用perl拷贝文件到另一个地方,但是所有可执行的文件拷贝过去都变成了普通文件。
也就是说perl没有连属性一起拷贝过去。
我试过File::Copy::copy和File::Copy::syscopy都不行。

因为要兼容Windows和Linux,我不太想写个条件分支来判断系统,然后用system来拷贝。

请大家帮帮忙,怎么解决这个问题?
...全文
618 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
aw325 2009-04-01
  • 打赏
  • 举报
回复
调用系统命令比较简单,但移植性不好。
xsir317 2009-04-01
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 fibbery 的回复:]
没有试过你所说的Copy包,也许与你copy时经历的中间过程有关系。因为不知道你的中间过程,所以,也就不好说了。

但是,就像楼上所说,system调用系统命令肯定没有问题。
可以通过全局变量$OSNAME/$^O来区分操作系统,变量解释如下:
$OSNAME
$^O
The name of the operating system under which this copy of Perl was built, as determined during the configuration process. The value is identical to $Config{'osname…
[/Quote]又学到了。。。
kindTerry 2009-03-31
  • 打赏
  • 举报
回复
如果你所说的用system命令拷贝可以达到要求的话,可以写个模块在里面根据OS判断所调用的copy命令
主程序里面使用该模块的拷贝函数,对用户就是透明的了
边城狂人 2009-03-31
  • 打赏
  • 举报
回复
如果没有办法实现带属性拷贝,那有没有办法实现
获取源文件的属性,再给新文件设置这些属性呢?
fibbery 2009-03-31
  • 打赏
  • 举报
回复
没有试过你所说的Copy包,也许与你copy时经历的中间过程有关系。因为不知道你的中间过程,所以,也就不好说了。

但是,就像楼上所说,system调用系统命令肯定没有问题。
可以通过全局变量$OSNAME/$^O来区分操作系统,变量解释如下:
$OSNAME
$^O
The name of the operating system under which this copy of Perl was built, as determined during the configuration process. The value is identical to $Config{'osname'}. See also the Config manpage and the -V command-line switch documented in the perlrun manpage.

In Windows platforms, $^O is not very helpful: since it is always MSWin32, it doesn't tell the difference between 95/98/ME/NT/2000/XP/CE/.NET. Use Win32::GetOSName() or Win32::GetOSVersion() (see the Win32 manpage and the perlport manpage) to distinguish between the variants.

iambic 2009-03-30
  • 打赏
  • 举报
回复
不清楚……
你这个需求可能比较少见,不知道有没有人做过现成的东西出来。

37,743

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧