【发布时间】:2017-09-13 16:32:29
【问题描述】:
我正在使用 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 界面。
【问题讨论】:
-
我认为问题在于
exec调用,它将您当前正在运行的可执行文件替换为新的。 -
感谢 @ulix 的这一点,我已经通过使用系统函数而不是 exec 调用来解决它。