Long-haired preachers come out every night,
Try to tell you what's wrong and what's right;
But when asked how 'bout something to eat
They will answer with voices so sweet:
You will eat, bye and bye,
In that glorious land above the sky;
Work and pray, live on hay,
You'll get pie in the sky when you die.
And that's where the phrase comes from. Here's a video of a chap called Blind Drunk Al singing it:
That was back in 1911 and Joe Hill was executed four years later for owning a red handkerchief (and/or murder).
In 1943, when the Americans had finally noticed that there was a war on and had decided to join in the fun, a pair of songwriters called Harold Adamson and Jimmie McHugh decided to write a stirring patriotic song. The melody by McHugh is actually rather similar to The Preacher and the Slave, but the words by Adamson are brave and hopeful and all-American:
What a show! what a fight!
Yes, we really hit our target for tonight.
The song is about a damaged warplane returning from a sortie. They've lost one of their engines and now they're Comin' in on a Wing and a Prayer. And that's where the phrase comes from.
Pie in the sky, like all food on airplanes, tastes horrid.