ssh -t and nohup

I have a fairly simple script like so:

nohup java -jar program.jar >> log 2>&1 &
echo $! > pidfile

This works great when using ssh server "script.sh" but not when using ssh -t server "script.sh"

The solution I came up with was to call sleep after recording the child pid. My guess at the problem is that the script and pseudo-tty are destroyed before the child process actually starts. Is there a better way to wait until the child starts before returning? Should I use something other than nohup to ensure the child starts?

I have to use ssh -t because of other constraints.

What's your shell? You might need the 'disown' command, otherwise, some shells'll try to do job control on the background process and wait for it to quit before it finishes. This doesn't happen without -t because no tty means no job control...

I'm using sh.

---------- Post updated at 07:32 PM ---------- Previous update was at 07:30 PM ----------

Which appears to be dash on the system I'm using.