Fix indices used to access arguments of external commands

fixes #5368