欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 汽车 > 维修 > SAP SM69命令无法处理带空格文件名

SAP SM69命令无法处理带空格文件名

2025/10/1 9:53:08 来源:https://blog.csdn.net/xiefireworks/article/details/143775767  浏览:    关键词:SAP SM69命令无法处理带空格文件名

背景:

        项目中有读取FTP加密文件并解密的需求,由于加密算法的限制,考虑采用OS命令解密的方式。

问题:

        经过测试发现对接系统生成的文件名含空格(文件生成为已有功能,不同意修改),当执行命令时解密失败。

解决:

        通过demo测试,发现通过函数SXPG_STEP_COMMAND_START调用OS命令无法处理文件名带空格的场景,最终增加一步脚本移除文件名中空格,考虑到脚本执行的可监控性,没有全部通过脚本处理。(如果还有其它处理这种场景的办法,欢迎留言)

如下为测试过程:

测试文件:/tmp/.demo 01.txt

执行结果:

双引号包括时无法识别双引号:

单引号自动添加转义或者外层套双引号:

转义符自动添加转义导致无法识别:

猜测标准函数处理时,将命令按空格分割后将文件名使用单引号或者双引号包含,因此无法通过转义符,单引号和双引号处理。

脚本代码(感谢AI):

#!/usr/bin/perluse strict;
use warnings;# 设置目标目录
my $target_dir = "/tmp/";# 检查目标目录是否存在
unless (-d $target_dir) {die "Error: Directory '$target_dir' does not exist.\n"; 
}# 打开目标目录并读取其中的所有文件和目录  
opendir(my $dh, $target_dir) or die "Cannot open directory '$target_dir' $!";
my @files = readdir($dh);
closedir($dh);# 过滤出文件(排除目录和特殊文件,如'.'和'..')
my @file_list = grep { -f "$target_dir/$_" && !/^\.{1,2}$/ } @files;# 遍历文件列表并重命名文件
foreach my $file (@file_list) {  # 构造原始文件路径my $old_filepath = "$target_dir$file";# 移除文件名中的空格my $new_filename = $file;$new_filename =~ s/ //g; # 使用正则表达式替换所有空格为空# 构造新文件路径my $new_filepath = "$target_dir$new_filename"; # 检查新文件名是否与旧文件名相同(避免不必要的重命名)if ($old_filepath ne $new_filepath) {# 检查新文件是否已存在  if (-e $new_filepath) {  # 如果新文件已存在,则删除它  unlink($new_filepath) or die "Cannot delete '$new_filepath': $!";  print "Deleted existing file '$new_filepath'\n";  } # 执行重命名操作rename($old_filepath, $new_filepath) or die "Cannot rename '$old_filepath' to '$new_filepath': $!";print "Renamed '$old_filepath' to '$new_filepath'\n";}
}print "All files in '$target_dir' have been renamed to remove spaces.\n";

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词