0

Perl / Tkがバッチコマンド(パスがハードコードされたローカルコマンド)を呼び出し、引数(ユーザーが選択した.csvファイル)を渡す必要があるGUIを準備する必要があります-ユーザーがGENERATEボタンを押したとき-ここでは簡略化されていますメモ帳で .csv ファイルを開くだけです。誰かが私を助けることができますか?

use Tk;


my $my_MW=MainWindow->new();
$my_MW->title("Sample application");
$my_MW->geometry("350x180-500+500");
$my_MW->resizable( 'no', 'no' );

my $my_Button=$my_MW->Button(-text=>"Select CSV Input File",-command=> \&get_file);
$my_Button->pack(-side=>"top",-expand=>1,-anchor=>"w",-padx => 20,-pady => 20);

my $filepath=" .... ";

my $my_Entry=$my_MW->Entry(-textvariable=> \$filepath);
$my_Entry->pack(-side=>"top",-expand=>1,-anchor=>"w",-padx => 20,-pady => 0,-fill=>"x");

my $my_Button1=$my_MW->Button(-text=>"GENERATE",-width => 12,-command=>sub{\&gen_rslt()});
$my_Button1->pack(-side=>"left",-expand=>1,,-pady => 20);
$my_Button1->configure(-state => 'disabled');

my $my_Button2=$my_MW->Button(-text=>"RESET",-width => 12,-command=>sub{\&clear_field()});
$my_Button2->pack(-side=>"left",-expand=>1,,-pady => 20);

my $my_Button3=$my_MW->Button(-text=>"EXIT",-width => 12,-command=>sub{exit()});
$my_Button3->pack(-side=>"left",-expand=>1,,-pady => 20);

MainLoop();

sub gen_rslt{

#Call the batch file and pass the file path as an argument!  
#batch file to open the file in notepad 
}

sub clear_field{
$my_Entry->delete(0,'end');
$my_Entry->insert(0," .... ");

$my_Button1->configure(-state => 'disabled'); 
}

sub get_file 
{
    $my_Entry->delete(0,'end');
  my @types =
       (["comma seperated files", [qw/.csv/]],
        ["All files",        '*'],
       );

  $filepath = $my_MW->getOpenFile(-filetypes => \@types) or return();
  $my_Button1->configure(-state => 'normal');  
}
4

1 に答える 1

0

systemコマンドを使用して、ファイルを開くことができます。例は

system("notepad.exe myfile.txt");

または、次のように使用することもできます

system(notepad.exe, $filepath);
于 2016-09-29T08:13:40.393 に答える