Dashcam footage from an Illinois police cruiser revealed last week an officer’s close call with a commuter train after gates didn't close and warning lights failed to go off.

Mokena police officer Peter Stanglewicz posted the video of the Nov. 9 incident to his Facebook account last week, giving people a firsthand look at how close he was to barreling into the train.

“Throughout my life, I've had very little luck. I've bought tons of raffle tickets, from little league tickets to charity raffles,” he wrote on Facebook. “Every lottery ticket was a loser. I just thought I wasn't born with luck at all. Little did I know, I had luck, I was just saving it all up for the perfect time. Here is all my luck being used ALL AT ONCE. If I never win anything again, I'm perfectly fine with that.”

CLICK HERE TO GET THE FOX NEWS APP

The frightening footage showed Stanglewicz driving past Schillings home improvement in Mokena and heading toward the tracks without the warning lights and gates activated, according to the Daily Southtown.

Stanglewicz reacts quickly and swerves to his left, narrowly missing the train.

Katie Dahlstrom, a Metra spokeswoman, told the Daily Southtown the train on the Rock Island District Line was heading toward LaSalle Street Station in Chicago when an electrical short caused an issue.

“A signal maintainer who had arrived on scene a few minutes earlier for a separate issue immediately started investigating this incident and put additional protections in place to prevent trains from proceeding through the intersection until the problem could be fixed,” she told the newspaper.

Mokena police said Wednesday they were “thankful” there were no injuries in the incident.