0
我需要訪問位於nfs裝入路徑中的文件。 訪問後,我需要看到一個掛起。如果掛起成功,那麼我的場景就會通過。 如果我看到「權限被拒絕」或訪問成功,則場景失敗。如何處理perl中的掛起方案?在訪問文件
我該怎麼辦?掛起後,我如何退出/終止該操作並繼續執行我的程序的下一組步驟。我目前正在這樣做。 我可以做這樣的事情,如果(睡眠= 10秒){
The subroutine takes the command to execute, file path.
sub access_timeout($$) {
my $cmd = shift;
my $file_path = shift;
print(qq{Running the command "$cmd $file_path" on the client});
# Here, I need to handle sleep. Sleep is expected case here. something like if ($result = sleep(10)) { success}
my $output = $client=>execute(command => qq{$cmd $file_path && echo _OK_});
if ($output =~ /(.*)_OK_/s) {
croak(qq{Expected a hang, access should not work});
} elsif ($output =~ /permission denied/s || $output =~ /No such file or directory/s) {
croak(qq{expected a hang but there is response});
}
}
出於好奇,在失敗時運行輸出'_OK_'的命令是什麼,並掛在成功上? – ThisSuitIsBlackNot 2015-03-02 20:12:20
對於掛起,我現在沒有在上面的代碼中的任何東西。 我打算添加一個try-catch。如果訪問超時,我預計會有一個掛起。仍在測試這個。請指教。 – sfbayarea 2015-03-02 20:19:59
上面的「client => execute(command =>」命令是一種在客戶端執行命令的方法 – sfbayarea 2015-03-02 20:27:27