Weak demand hits factory output in July