There are probably better ways to achieve your goals (like using dup2 and fork or a popen kind of function), but if you're concerned with just getting all output, errors included:
@output = `( g++ j.cpp -o "prog" && ./prog ) 2>&1`
2>&1 will redirect stderr (fd 2) to stdout (fd 1) so it is included in your @output
mvds
2010-07-31 12:15:16