Error Bad File Descriptor 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 company Business Learn perl bad file descriptor windows more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags
Write Error Bad File Descriptor
Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like
Socket Error Bad File Descriptor
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 favorite 1 I'm trying
Wget Error Bad File Descriptor
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 File Descriptor" error and I cannot figure bad file descriptor error in c 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.9k24150390 asked Apr 28 '10 at 14:19 Magicked 3102817 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,16422543 How embarrassing... Yes, that was the problem. It is now fixed. Thanks! –Magicked Apr 28 '10 at 14:30 add a comme
Q&A Tutorials Poetry RecentThreads NewestNodes Donate What'sNew on Mar 19, 2007 at 16:25UTC ( #605517=perlquestion: print w/replies, xml ) Need Help?? digger has asked for the wisdom of the Perl Monks concerning the following question: Esteemed Monks, I have run into a strange python socket error bad file descriptor problem that I can't seem to get to the bottom of on my own, ls write error bad file descriptor so I come to the monestary seeking assistance. I have a script that watches a directory, and modifies some files before bad file descriptor linux moving them to an output directory. Fairly simple, and I have done similar work before without any problems. This time I am getting a bad file descriptor error when creating the output file. I have http://stackoverflow.com/questions/2730270/why-do-i-get-bad-file-descriptor-when-i-try-to-read-a-file-with-perl tried File::Copy, Win32::CopyFile and simply writing the data to the file during processing, and I get the same error each time. The really strange part is that when I use File::Copy or Win32::CopyFile, I get the output file as requested along with the error. When I use the standard print FILE $data, the write fails and I get no file. Thanks for any assistance/pointers, digger open(FILE,"<",$file); binmode(FILE); if (flock(FILE,LOCK_EX|LOCK_NB)) http://www.perlmonks.org/?node_id=605517 { my $buf = ""; report("Info: Processing $file"); #make sure this is a pcl job file first #if not, move it and log it read(FILE,$buf,9); $printstring = $printstring.$buf; unless($buf =~ m/^\x1B\x25\x2D\x31\x32\x33\x34\x35\x58 +/) { close(FILE); my $errdir = "$dir\\ERR"; report ("Warning: $file is not a valid PCL file - +moving to ERR folder"); unless(-d $errdir){mkdir($errdir);} move($file,$errdir); next; } while(read(FILE,$buf,4096)) { fixtraycalls(\$buf); $printstring= $printstring.$buf; } close FILE;#closing file flushes buffer and releases l +ock if($keepfile) { my $dest; sleep 1; eval{ $dest = $$appconfig{"destination"}."\\$filenam +e"; Win32::CopyFile($file,$dest,1); }; if($!) { report("Error: Unable to move file to destinat +ion - ".$dest."\n $!"); #die; } } [download] Comment on Bad File Descriptor ErrorSelect or Download Code Replies are listed 'Best First'. Re: Bad File Descriptor Error by Anno (Deacon) on Mar 19, 2007 at 17:20UTC ... when I use File::Copy or Win32::CopyFile, I get the output file as requested along with the error. The error variable $! is only valid immediately after an actual system error, which must be recognized by other means. If $! is nonzero that doesn't indicate an error in the preceding code. The value can come from anywhere. So you are using it wrong in your code below. if($keepfile) { my $dest; sleep 1; eval{ $dest = $$a
at line 94 " - PERL Beginners Hi all, Can someone give me a hand understanding why I am getting this error. This script http://www.justskins.com/forums/why-bad-file-descriptor-126470.html telnets into a telnet server (cisco) then telnets into other cisco router https://bytes.com/topic/perl/answers/844076-bad-file-descriptor 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 bad file of them. I have a feeling it 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, bad file descriptor Can someone give me a hand understanding why I am 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"; $usern
tips & solutions from a community of 418,504 IT Pros & Developers. It's quick & easy. Bad file descriptor P: 30 anklos Hi, everyone I met a "Bad file descriptor" problem, and I test my var, it is right in the proceeding. I dont know why, any suggestion is helpful [ Expand|Select|Wrap|Line Numbers $dir="d:/1"; #print"Textfilesin$dirare:\n"; opendir(HANDLE,$dir)ordie"Can'topen$dir:$!"; while(defined($file=readdirHANDLE)) { nextif$file=~/^\./; $dir2=$dir."/".$file; &removedir($dir2); } closedir(HANDLE); subremovedir { opendir(HANDLE2,$_[0])ordie$!; #print"$_[0]\n"; while(defined($file2=readdirHANDEL2)ordie$!) { print"$_[0]/$file2\n"; nextif$file2=~/^\./; if(-d"$_[0]/$file2") { $_[0].="/".$file2; &removedir($_[0]); } unlink"$_[0]/$file2"; } closedir(HANDLE2); rmdir$_[0]; } "while(defined ($file2=readdir HANDEL2) or die $!)" <------ "bad file descriptor" died out here. Thanks in advance. Oct 8 '08 #1 Post Reply Share this Question 3 Replies Expert 2.5K+ P: 4,059 KevinADC look at how you have HANDEL2 spelled Oct 8 '08 #2 reply P: 30 anklos look at how you have HANDEL2 spelled I'm sorry for inattention. Thank you, Kevin. Oct 8 '08 #3 reply Expert 2.5K+ P: 4,059 KevinADC I'm sorry for inattention. Thank you, Kevin. We've all done it. Glad it was an easy one. Oct 8 '08 #4 reply Message Cancel Changes Post your reply Join Now >> Sign in to post your reply or Sign up for a free account. Similar topics Is it possible to get a file name from the file descriptor returnedby Low-Level I/O API open? Release file descriptor in c/c++ extracting file from the file descriptor how to use proc_open and a non-standard file descriptor Error from AOL: Deferred: Bad file descriptor? dup(0) failed after 3195 successes: Bad file descriptor Stream from file descriptor? File descriptor turns to 0! Convert File Descriptor to ofstream object file.readlines() - gives me error (bad file descriptor) Browse more Perl Questions on Bytes Question stats vi