Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
系统命令在Perl脚本中工作不正常_Perl - Fatal编程技术网

系统命令在Perl脚本中工作不正常

系统命令在Perl脚本中工作不正常,perl,Perl,使用Perl脚本更改特定目录的权限。脚本正在正常运行,但未更改目录的权限 system("chmod 0777 $dir"); $dir:路径在此变量中声明 设置权限失败。我无法告诉您命令失败的原因,因为您没有提供足够的详细信息,但在本例中不需要使用system,因为Perl内置了chmod,其行为完全相同 use strict; use warnings; my $dir = "/some/dir"; chmod 0777, $dir or die "$!"; 如果命令失败,这也会给您一

使用Perl脚本更改特定目录的权限。脚本正在正常运行,但未更改目录的权限

system("chmod 0777 $dir");
$dir
:路径在此变量中声明


设置权限失败。

我无法告诉您命令失败的原因,因为您没有提供足够的详细信息,但在本例中不需要使用
system
,因为Perl内置了
chmod
,其行为完全相同

use strict;
use warnings;

my $dir = "/some/dir";
chmod 0777, $dir or die "$!";
如果命令失败,这也会给您一条有效的错误消息

您还可以创建目录和文件列表

use strict;
use warnings;

my @dirs = ("dir1", "dir2");
my $each = chmod 0777, @dirs;
print "$each modified\n";
die $! if ($!);

尝试使用
系统(“chmod 0777$dir”)运行脚本,并执行“无法更改权限”进行错误检查。为什么需要使用系统?Perl内置了
chmod
。。只需尝试
chmod'0777',$dir
@sergiotarxz,但这将导致自定义错误消息<代码>系统(“chmod 0777$dir”)或骰子“$!”
请回答您的问题并提供答案。包括文件的当前所有者和权限,以及在哪个用户(和组)下运行代码。包括所提到的
和模具…
零件@sergiotarxz。你能
chmod
外壳上的文件吗?@GerhardBarnard应该是
和die
,而不是
或die
system
成功返回
0
。我会在错误消息中包含
$dir
。在第二种情况下,成功的
chmod
不会设置
$
0
,所以你不能依赖它。您需要检查
$each==@dirs