Bad File Descriptor Error Perl
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the perl read bad file descriptor company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions
Perl Filehandle
Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million perl bad file descriptor windows programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Why do I get “Bad File Descriptor” when I try to read a file with Perl? up vote 1 down vote bad file descriptor error in c favorite 1 I'm trying to read a binary file 40 bytes at a time, then check to see if all those bytes are 0x00, and if so ignore them. If not, it will write them back out to another file (basically just cutting out large blocks of null bytes). This may not be the most efficient way to do this, but I'm not worried about that. However, right now I'm getting a "Bad
Write Error Bad File Descriptor
File Descriptor" error and I cannot figure out why. my $comp = "\x00" * 40; my $byte_count = 0; my $infile = "/home/magicked/image1"; my $outfile = "/home/magicked/image1_short"; open IN, "<$infile"; open OUT, ">$outfile"; binmode IN; binmode OUT; my ($buf, $data, $n); while (read (IN, $buf, 40)) { ### Problem is here ### $boo = 1; for ($i = 0; $i < 40; $i++) { if ($comp[$i] != $buf[$i]) { $i = 40; print OUT $buf; $byte_count += 40; } } } die "Problems! $!\n" if $!; close OUT; close IN; I marked with a comment where it is breaking. Thanks for any help! perl filehandle share|improve this question edited Apr 28 '10 at 16:10 brian d foy 86.7k24149388 asked Apr 28 '10 at 14:19 Magicked 3002817 You may also want to read stackoverflow.com/questions/1479741/… and apply the practices therein. Global filehandles can lead you to a world of hurt later on when you're least expecting it. –Ether Apr 28 '10 at 14:45 add a comment| 1 Answer 1 active oldest votes up vote 4 down vote accepted You might want to check if open doesn't return error. open IN, "<$infile" or die "Can't open $infile: $!"; share|improve this answer answered Apr 28 '10 at 14:27 Dmitry Yudakov 9,15422543 How embarrassing... Yes, that was the problem. It
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack socket error bad file descriptor Overflow the company Business Learn more about hiring developers or posting ads with us Stack bad file descriptor python Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community
Bad File Descriptor Golang
of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Perl select return “bad file descriptor” error up vote 1 down vote favorite I am trying to http://stackoverflow.com/questions/2730270/why-do-i-get-bad-file-descriptor-when-i-try-to-read-a-file-with-perl implement inter process communication using pipes and the select command. Here is a first try: use warnings; use strict; use feature qw(say); use IO::Select; use IO::Handle; my @rh; my %childs; my $numChilds=2; $SIG{CHLD}='IGNORE'; #Reap childs automatically for my $i (1..$numChilds) { pipe(my $pread, my $pwrite); push(@rh,$pread); $pwrite->autoflush(1); my $child = fork(); if ($child==0) { runChild($i,$pwrite); } $childs{$pread->fileno()}={pid=>$child,id=>$i,i=>0}; } my $sel = IO::Select->new( @rh ); while (1) { say "Running select.."; my http://stackoverflow.com/questions/25581407/perl-select-return-bad-file-descriptor-error @ready = $sel->can_read; last if (! @ready); for my $fh (@ready) { say "Processing file descriptor ".($fh->fileno()); chomp(my $line=<$fh>); my $fd=$fh->fileno(); my $child=$childs{$fd}->{id}; say "Got line: \"$line\".."; my $nmsg=($childs{$fd}->{i})+1; if ($nmsg==2) { $fh->close(); $sel->remove($fh); say "Select count: ".($sel->count()); say "Closed fh $child.."; } else { $childs{$fd}->{i}=$nmsg; } } } say "Done."; sub someSeconds { return int(rand(4))+3; } sub runChild { my ($i, $pipe)=@_; sleep (someSeconds()); print $pipe "Child $i says: A\n"; sleep (someSeconds()); print $pipe "Child $i says: B\n"; exit 0; } The output is: Running select.. Processing file descriptor 4 Got line: "Child 2 says: A".. Running select.. Processing file descriptor 3 Got line: "Child 1 says: A".. Running select.. Processing file descriptor 4 Got line: "Child 2 says: B".. Select count: 1 Closed fh 2.. Running select.. Done. The problem is that the last message from child 1 is missing Got line: "Child 1 says: B". I run strace prog.pl which gave: select(8, [3 4], NULL, NULL, NULL) = -1 EBADF (Bad file descriptor) on the last select call.. perl share|improve this question edited Aug 30 '14 at 11:56 ikegami 202k7132308 asked Aug 30 '14 at 10:32 Hakon Hægland 8,54352260 add a comment| 1 Answer 1 active oldest votes up vote 2 down vote accepted $fh->close(); $sel->remove($fh); You must first remov
at line 94 " - PERL Beginners Hi all, Can someone give me a hand understanding why I am getting this error. This script telnets into a http://www.justskins.com/forums/why-bad-file-descriptor-126470.html telnet server (cisco) then telnets into other cisco router to grab there configs. I get these errors when trying to connect to certain routers (5, 11,12,13,14). If I look in my dump logs I see that the device didn't echo anything back. I have play with some control and break commnads wich help but doesn't fix all of them. I have a feeling it bad file has something to so with the filehandle or buffer but not sure. Either case can anyone ... Thread Tools Show Printable Version Email this Page… Subscribe to this Thread… Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode January 26th,11:03 PM #1 why "Bad file descriptor at line 94 " Hi all, Can someone give me a hand understanding why I am bad file descriptor getting this error. This script telnets into a telnet server (cisco) then telnets into other cisco router to grab there configs. I get these errors when trying to connect to certain routers (5, 11,12,13,14). If I look in my dump logs I see that the device didn't echo anything back. I have play with some control and break commnads wich help but doesn't fix all of them. I have a feeling it has something to so with the filehandle or buffer but not sure. Either case can anyone tell me why I am getting Bad file descriptor at line 94 ?? I have the line marked **** This is my first perl script so please don't laugh ;-( This is ussing active state on an XP machine. This is perl, v5.6.1 built for MSWin32-x86-multi-thread (with 1 registered patch, see perl -V for more detail) thanks for any help #!/perl/bin/ # Uses Net::Telnet::Cisco module # Uses Net::Telnet module # Uses Time-local module ## **My $vars $host = "10.4.1.10"; $TFTPSERVER = "10.4.1.238"; $username = "user"; $password = "pass"; $enpassword = "pass"; $filename = "dump.txt"; $file = "input.txt"; $errorlogfilelast = "c:/perl/bin/myerrorloglast.txt"; $errorlogfileall = "c:/perl/bin/myerr