I'm not certain I can help with the specific problem without knowing more about $prog. However, I wonder if when you say you tried
open, you meant to say
exec instead, because
open and system are not similar system and
exec are similar.
Updated: monkey_boy points out below how system and open can indeed be similar, but without knowing what $prog is doing I don't know that it can be assumed to be so in this case. However, I updated the text above to say what I mean more clearly.
My apologies to open, I meant no disrespect.