Getting an extra "$ " before my program output on Unix [#IP1]

I have gotten rid of the extra newlines with code based on this answer. However, some programs just freeze the shell if their help is too long (for instance, java.exe which outputs it’s help all at one time, vs. jar.exe which only outputs a small amount of its help).