捕获文件i / o错误 [英] trapping file i/o error

查看:93
本文介绍了捕获文件i / o错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在大多数perl示例中,它使用此方法来捕获错误:


open(INFILE,$ fname)或die无法打开$ fname" ;;

process_file();

关闭(INFILE)

other_codes();


既然如果我不想在开放后死去以便运行

other_codes()?我可以测试文件句柄INFILE的值,就像我用b做的那样
吗?


fhandle = fopen(fname," r")

if(fhandle> 0){

process_file();

fclose(fhandle)

}

else

show_error()

other_codes();


-

。〜。可能,勇气,愿景。在我们信任的Linux中。

/ v \ http:// www .linux-sxs.org

/(_)\ Linux 2.4.22-xfs

^ ^ 5:00 pm up 2 days 18:54 load平均值:1.00 1.00 1.00


In most perl examples, it used this method to trap error:

open(INFILE, $fname) or die "Unable to open $fname";
process_file();
close(INFILE)
other_codes();

Now that if I don''t want to die after the open so as to run
other_codes()? Could I test the value of file handle INFILE like what I
did with C?

fhandle=fopen(fname,"r")
if (fhandle > 0) {
process_file();
fclose(fhandle)
}
else
show_error()
other_codes();

--
.~. Might, Courage, Vision. In Linux We Trust.
/ v \ http://www.linux-sxs.org
/( _ )\ Linux 2.4.22-xfs
^ ^ 5:00pm up 2 days 18:54 load average: 1.00 1.00 1.00

推荐答案

fname)或死亡无法打开
fname) or die "Unable to open


fname";

process_file();

关闭(INFILE)

other_codes();


现在如果打开后我不想死,以便运行

other_codes()?我可以测试文件句柄INFILE的值,就像我用b做的那样
吗?


fhandle = fopen(fname," r")

if(fhandle> 0){

process_file();

fclose(fhandle)

}

else

show_error()

other_codes();


-

。〜。可能,勇气,愿景。在我们信任的Linux中。

/ v \ http:// www .linux-sxs.org

/(_)\ Linux 2.4.22-xfs

^ ^ 5:00 pm up 2 days 18:54 load平均值:1.00 1.00 1.00
fname";
process_file();
close(INFILE)
other_codes();

Now that if I don''t want to die after the open so as to run
other_codes()? Could I test the value of file handle INFILE like what I
did with C?

fhandle=fopen(fname,"r")
if (fhandle > 0) {
process_file();
fclose(fhandle)
}
else
show_error()
other_codes();

--
.~. Might, Courage, Vision. In Linux We Trust.
/ v \ http://www.linux-sxs.org
/( _ )\ Linux 2.4.22-xfs
^ ^ 5:00pm up 2 days 18:54 load average: 1.00 1.00 1.00


toylet写道:

在大多数perl示例中,它使用此方法来捕获错误:

打开(INFILE,

In most perl examples, it used this method to trap error:

open(INFILE,


这篇关于捕获文件i / o错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆