Wolverhampton man Derek Philips, now 56 years old, hid in his former partner's Bridgnorth home in January 2019 despite a restraining order barring him from going near her.
Philips, of Prosser Street, Park Village, entered the building using a key while his victim was out with her new partner.
He opened doors and cupboards before removing the lightbulb outside a full-length cupboard and hiding away behind some coats in the back.
When the woman and her partner returned, they were unnerved enough by the signs of a disturbance to ask some of her friends to stay for a while.
Later that night, the woman's partner saw Philips emerge from the cupboard holding the blade.
"He saw that the defendant had the knife raised," said prosecutor Mr Omar Majid to Shrewsbury Crown Court today.
"He instinctively grabbed the defendant's arm to try and disarm him."
A scuffle began and the male victim suffered a dislocated thumb while Philips was forced into the kitchen.
He was shouting to the man: "I'm not here for you," the court heard.
The police, as well as the woman's stepfather, were called, and while they were on their way Philips escaped through the kitchen window.
But he texted the woman to say he had left his shoes in the cupboard.
The victims did indeed find a pair of shoes and a cap in the back of the cupboard.
The court heard the male victim and the stepfather urinated on the shoes.
Philips was arrested soon afterwards and he was brought to Shrewsbury Crown Court this week to be sentenced for affray and for breaching the restraining order.
Both defendants reported fearing for their lives during the incident.
The court heard the victim is a vulnerable woman and about 30 years younger than Philips.
He has several multiple convictions for hurting her, including for putting her in a chokehold.
Defending Philips, Mr Timothy Sapwell said: "The last few years have been an aberration.
"[The offending] is all down to the fact he was taking cannabis but he doesn't do that anymore."
He said that the victim would often invite Philips to her home and ask to buy drugs from him.
Recorder Francesca Levett heard the case. She said: "For the third time in two years, you have been convicted of offences involving your former partner, who is a young and vulnerable woman.
"It is clear that you can't leave her alone."
She sentenced Philips to two years in jail for the affray offence, and one year to run concurrently for breaching the restraining order.
She also extended the order and made it indefinite, meaning that from now on he is banned from having any contact with his victim or from even entering Bridgnorth.