The 34-year-old right-hander gave up two runs on seven hits, striking out six and walking none.
"I felt good," said Hernandez, who went 4-0 with a 3.52 ERA this spring. "I hope to continue to pitch like that. I just need to keep the ball down and don't overthrow, and I'll be good."
Hernandez struggled early, as the Hooks got to him for six hits and two runs in the first few frames. After giving up an RBI single to Colin Moran in the first inning, Hernandez escaped a jam with runners on second and third by striking out Conrad Gregor.
He gave up a leadoff homer to Telvin Nash in the second, then two more hits before escaping another jam with an infield pop and a strikeout.
He allowed just one baserunner the rest of the way.
"I think he got a little mad at the end after he had guys hitting him around the ballpark a little bit early on," manager A.J. Hinch said. "He settled in and really pitched well. He threw 90 pitches and looked good. He has his first start for us against the Texas Rangers in a little more than a week, and he'll be ready."
The Astros' offense also struck early, with Jose Altuve, who went 2-for-3 before being pulled in the fourth inning, leading off with an infield single and being driven home on a Luis Valbuena double.
Houston took control when Jed Lowrie hit a bases-loaded double that one-hopped the center-field wall, driving in two runs. Robbie Grossman added to the lead with a two-run single up the middle that put the Astros up, 5-2.
The Astros tacked on two more in the eighth on a two-run double from catcher Hank Conger, who finished 2-for-4.
Twenty-year-old phenom Carlos Correa, who hit .341 during Grapefruit League action, blasted a two-run homer in the eighth inning for the Hooks off Astros reliever Darin Downs. The No. 1 Draft pick of 2012 added a double in the ninth inning to go 2-for-5 for the night.
"We got out of this one healthy, and everyone got to play, so that's what we were looking for," Hinch said. "We're definitely ready to get to Houston and get the season started."
Up next: The Astros return to Houston for two final exhibition games against the Royals on Friday and Saturday at Minute Maid Park. Scott Feldman will start Friday's game, with Collin McHugh going Saturday. The Astros open the regular season at home on Monday night against the Indians.