Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
Perl: the Markov chain saw
 
PerlMonks  

JPEG cgi problem

by mouser13 (Novice)
on Oct 28, 2012 at 14:47 UTC ( #1001270=perlquestion: print w/ replies, xml ) Need Help??
mouser13 has asked for the wisdom of the Perl Monks concerning the following question:

Hello I'm having a bit of issue I have thrid party program that builds a JPEG(JFIF really). For some reason when I try to read it in perl binmode it removes the header information. Server code recieves plot to build and passes back the image data
print `/cwms/s0cwmsxx/v1.5.01/bin/dssVue $LINE.py /cwms/g7cwmspd/plot +Files/files/$num`; print "After command\n"; open(FH, "/cwms/g7cwmspd/plotFiles/files/$num.jpg"); binmode(FH); my $buf; while(<FH>) { read(FH,$buf,500); print $buf; print $client $buf; }
client(cgi) sends the message to build the plot and print out the image
print "Content-type: image/jpeg\n\n"; print $socket "$MESSAGE\n"; read($socket, $buffer,2097152); print "Content-type: image/jpeg\n\n"; print substr($buffer,1); open (OUTIMAGE,">/usr26/wcdb/log/plottest.jpg"); binmode(OUTIMAGE); print OUTIMAGE substr($buffer,1); close(OUTIMAGE);
Any ideas why I'm not getting the first 200 or so bytes of header information? Ie.I ftp both files one created by the thrid party program and the one from my reading it. The one created by the thrid party program starts JFIF    C  and is 77,737. Looking closely it does have The below in it. So to me it looks like for somereason binmode perl is not read maybe the header information of the JPEG? My reading starts   } !1AQa"q2#BR$3br and is 77,528 bytes and doesn't work correctly.

Comment on JPEG cgi problem
Select or Download Code
Re: JPEG cgi problem
by NetWallah (Monsignor) on Oct 28, 2012 at 15:14 UTC
    Your "while(<FH>)" is reading a record into $_, which you are not using.

    Change to:

    while( ! eof FH )
    or the equivalent.

                 "By three methods we may learn wisdom: First, by reflection, which is noblest; Second, by imitation, which is easiest; and third by experience, which is the bitterest."           -Confucius

Re: JPEG cgi problem
by aitap (Chaplain) on Oct 28, 2012 at 20:49 UTC
    Please post hexdumps if you want to show binary data.
    Sorry if my advice was wrong.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1001270]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (13)
As of 2014-04-25 08:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (585 votes), past polls