I think I've figured out the problem here, by excerpting code from BatchDebayer into a test script copied below.
Hypothesis: BatchDeBayer opens the image in the script (first three lines of code below). At this point, the image is already rotated (if necessary) and debayered. But for some reason, BatchDeBayer creates a Debayer object and executes it on this already-debayered image (probably so that options different than the default can be used). If no rotation is involved, this works fine. But if the input image has already been rotated, then the call to Bayer.execute will use the wrong debayer pattern. The code below should be run with an image that specify's rotation 90 degrees clockwise, and with the DSLR_RAW "No image flip" preference unset. The first image "test-result" is corrupted by debayering with the wrong pattern. The second image "test-result-fixed" corrects the problem by specifying the rotated debayer pattern. If the DSLR_RAW "No image flip" preference set, the opposite occurs: test-result is the same as test-input and "test-result-fixed" is corrupted because it uses the wrong debayer pattern.
By the way, the dcraw call displayed in the console is the first one from the ImageWindow.open() call, not the later call to dcraw that generates the output image.
John
/// Demonstrate bug in BatchDeBayer
var inputImageWindow = ImageWindow.open("/Users/pane/Desktop/video tmp/BatchDeBayer bug investigation/JFP_4539.CR2")
var sourceView = inputImageWindow[0].mainView;
sourceView.window.saveAs("/Users/pane/Desktop/video tmp/BatchDeBayer bug investigation/test-input.xisf", false, false, false, false );
// if image should be rotated and the DSLR_RAW "No image flip" preference is unset, this demonstrates the issue
// the image loaded above is already rotated and debayered. the script runs debayer again on this image, but
// because it has rotated the bayer pattern is wrong.
var p = new Debayer;
p.bayerPattern = p.RGGB;
p.debayerMethod = p.VNG;
p.evaluateNoise = true;
p.executeOn( sourceView )
var resultView = View.viewById( p.outputImage );
resultView.window.saveAs("/Users/pane/Desktop/video tmp/BatchDeBayer bug investigation/test-result.xisf", false, false, false, false );
resultView.window.forceClose();
var p2 = new Debayer;
p2.bayerPattern = p2.GRBG;
p2.debayerMethod = p2.VNG;
p2.evaluateNoise = true;
p2.executeOn( sourceView )
var resultView2 = View.viewById( p2.outputImage );
resultView2.window.saveAs("/Users/pane/Desktop/video tmp/BatchDeBayer bug investigation/test-result_fixed.xisf", false, false, false, false );
resultView2.window.forceClose();