The film Paths of Glory is based off the Humphrey Cobb book of the same name. As you note there is a divergent screenplay with a happier ending. According to producer James B Harris Kubrick chose to have the film end the same way that the book does to preserve its integrity. The reality of the movie is very much the reality of the war.
Broulard explains his reasoning for what he does in his final meeting with Colonel Dax.
Colonel Dax, you're a disappointment to me. You have spoiled the keenness of your mind by wallowing in sentimentality.
You really did want to save those men, and you were not angling for Mireau's command. You're an idealist, and I pity you, as I would the village idiot.
We're fighting a war, a war we've got to win.
Those men didn't fight, so they were shot.
You bring charges against General Mireau, so I insist that he answer them.
Wherein have I done wrong?
In Broulard's eyes Mireau ordering the artillery to shell his own troops does not mean the men are innocent. The French Army Code at the time stated "discipline is the main strength of armies, it is important that a superior receives a subordinate’s entire obedience and submission at all times." That means you die if ordered to do so.
The book is based on an incident called the Souain Corporals Affair that occurred in March 1915 during World War I. In that event on March 10 the French artillery accidentally shelled part of their own line and the area between the French and German trenches. This was supposed to be a strike against German machine guns in preparation for a morning assault. With the German guns still in place and the ground between the trenches now destroyed, the attack quickly became a slaughter. The remaining French troops refused to leave the trenches.
Division General Géraud Réveilhac ordered the French artillery to fire on their own troops to force them out of the trenches and into an attack. As in the movie and book the artillery commander refused to do so without a written order. General Réveilhac then ordered the company commander Captain Equilbey to produce a list of 24 men that would include six corporals and 18 enlisted men chosen from the two youngest members in every squad. These men would be court-martialed as an example of what happens when you fail to follow orders.
On March 16, 1915 trial was held and all 24 men were sentenced to die. However, the 18 enlisted men received a stay of execution because they had been randomly chosen. Two of the corporals also received a stay after it was determined that they did not hear the order to attack. In the end four corporals were executed on March 17. Two hours after their execution though word reached the camp that the French High Command had commuted the death sentences to forced labor. In the film one soldier from each of the three companies is chosen to be executed for cowardice for refusing to attack the German line.
The four corporals were eventually exonerated in 1934 due to the efforts by relatives of the four. General Réveilhac was eventually relieved of his front line command and moved to a reserve command for the rest of the war. He was made a Grand Officer of the Legion of Honor at the end of the war, France's highest order of military merit. In 1921 as the case became more well known he was condemned even by the military press. He attempted to have a letter published defending his actions but the Minister of War felt it would only bring more attention to the case.