Hi, Phil, Bogdan!
Dear Phil, of course I didn't replace :-) I thought JPGDIR and CR2DIR were parameters of command. I've only put all files and ExifTool in one directory. I'll try again tonight at home, now at work I haven't RAWs. Thanks a lot!
Dear Bogdan, you are perfectly right! I didn't think about it. For instance, I usual hold camera verticaly when right hand is on top, but very rarely I hold it left on top. My wife always holds it left hand on top. And it is interesting, that camera always knows how to rotate image. That's why I suppose (I don't know subject as well as you do, I only can suppose) that there is a tag in RAW, which tells how rotate image. And if you replace this tag, it doesn't matter, how JPEG 'lies' inside RAW - top on right or top on left. If you know, that JPEG is vertical, you rotate it (to any side) and write about sense of rotation in RAW tag.
If tag already exists in RAW....
...Hum... I have next idea. Orientation of RAW and embedded JPEG must be the same. If there is no information in RAW file about orientation, and JPEG is vertical, it is real problem. And I really don't know how to solve this problem correctly. If there is no information in RAW and JPEG is horizontal, we can embed it 'as is'. If there is information in RAW about orientation, and JPEG is vertical, we can determine where must be top and rotate JPEG correctly. If JPEG is already horizontal, I think it is no need to do any rotation.
Of course, it is only my supposition. May be it is better for me to not impede and to wait the result from you :-) In any case I'm ready to test your program when you finish.