【发布时间】:2020-08-10 00:56:55
【问题描述】:
我正在尝试在 Perl 脚本中运行 bash 命令。我正在使用system("file --mime-type $fileName);,但在其他命令(例如ls or pwd)工作时它不起作用。
在终端中,它显示“无法打开'Paper(文件名)'(没有这样的文件或目录)。
以下是我的代码:-
foreach my $a(@ARGV)
{
opendir(DIR, $a) or die "You've Passed Invalid Directory as Arguments or $!\n";
while(my $fileName = readdir DIR)
{
next if $fileName =~ /^\./; #this is to remove dotted hidden files.
system("file --mime-type $fileName");
print $fileName,"\n";
}
closedir(DIR);
}
请看终端报错截图:
我想知道为什么这不像其他命令那样工作?当我仅在终端中键入此命令时,它会正确显示文件类型,但不会在 Perl 脚本中显示。 一些帮助将不胜感激。
【问题讨论】: