##
print 'echo $?';
# $ssh->exec('echo $?' . "\n")
####
$ssh->exec('your-program; echo $?');
####
$ssh->exec('./shellscript-that-runs-your-program-and-then-outputs-dollar-question-mark.sh');
# where shellscript-that-runs-your-program-and-then-outputs-dollar-question-mark.sh
# contains the lines:
#
# #!/bin/sh
# your-program
# echo $?