浏览目录上的perl tk窗口自封



我正在使用Perl的TK模块开发桌面客户端。我有一个按钮为特定任务打开目录。但是我面临的问题是关闭我不想的perl界面。

下面是实现目录逻辑打开的子:

sub open_directory {
  my $directory = shift;
  print "comes here atleast for $directory";
  if ($^O eq 'MSWin32') {
    exec "start $directory";
  }
  else {
    die "cannot open folder on your system: $^O";
  }
} 

我正在通过:

来打电话
sub second_window{
    my $row = 0;
    $mw2 = new MainWindow; 
    #Loop for listing taskname,path and browse button for all tasks of a region
    for my $i(1..$#tasks_region_wise){
        $row = $row+1;
        $frame_table-> Label(-text=>$sno+$i,-font=>"calibri")->grid(-row=>$row,-column=>0,-sticky=>'w');
        $frame_table-> Label(-text=>$tasks_region_wise[$i][2],-font=>"calibri")->grid(-row=>$row,-column=>1,-sticky=>'w');
        $frame_table-> Label(-text=>$tasks_region_wise[$i][3],-font=>"calibri")->grid(-row=>$row,-column=>2,-sticky=>'w');

#Calling that sub in the below line:
        $frame_table->Button(-text => 'Browse',-relief =>'raised',-font=>"calibri",-command => [&open_directory, $tasks_region_wise[$i][3]],-activebackground=>'green',)->grid(-row=>$row,-column=>3);
        $frame_table->Button(-text => 'Execute',-relief =>'raised',-font=>"calibri",-command => [&open_directory, $tasks_region_wise[$i][4]],-activebackground=>'green',)->grid(-row=>$row,-column=>4);
        $frame_table->Button(-text => 'Detail',-relief =>'raised',-font=>"calibri",-command => [&popupBox, $tasks_region_wise[$i][2],$tasks_region_wise[$i][5]],-activebackground=>'green',)->grid(-row=>$row,-column=>5);
    }
    $frame_table->Label()->grid(-row=>++$row);
    $frame_table->Button(-text => 'Back',-relief =>'raised',-font=>"calibri",-command => &back,-activebackground=>'green',)->grid(-row=>++$row,-columnspan=>4);
    MainLoop;
}

它正确打开文件资源管理器窗口,但关闭了perl接口。

发布以将来引用面临此问题的任何人。我刚刚得到了一个适当的问题,如stackoverflow用户@ulix所评论的那样。

问题:这里的问题是,EXEC调用导致此当前脚本执行并执行了Start Directory命令。

解决方案:将Exec调用转换为系统调用,该调用不会启动EXEC并由Perl处理。

pfb sub的更新代码:

sub open_directory {
  my $directory = shift;
  print "comes here atleast for $directory";
  if ($^O eq 'MSWin32') {
    system("start $directory");
  }
  else {
    die "cannot open folder on your system: $^O";
  }
} 

最新更新