chunk_length is dependent on 'cmd' in java_upload_part not 'exec_cmd':

Should be @payload_exe.length + append.length + constant to cover cmd. NB append changes AFTER chunk_length is set so chunk length will change after the initial loop.