This is a longstanding problem with psexec input. Issue seems to be with the handling of pipes, basically what the user enters on the
set/p line gets broken into multiple inputs and fed piecewise to the batch file, which of course is not the way it's supposed to work.
The closest to a pure
psexec solution is the batch snippet posted by user
qazy on SysInternals' own PsExec forum at http://forum.sysinternals.com/psexec-do-not-recog-p_topic5101_post137110.html#137110 (incidentally, the thread was started back in 2006, and qazy's reply came in 2012). The code basically anticipates the broken input, and attempts to reassemble the pieces into a single string. It mostly works, though in my experience it sometimes requires an extra ENTER key to end a line input.
An alternative that I found more recently is
paexec from https://www.poweradmin.com/paexec/ (obligatory disclaimer: I have no affiliation/interest with/in
poweradmin whatsoever, but I like the fact that their
paexec is open sourced, and I have used it for real-life chores).
As it happens,
paexec seems to get this input piping right. Batch file
set /p "ip=Enter the ip: "
set /p "sub=Enter the sub: "
echo %ip% subnet mask %sub%
C:\etc>paexec \\otherpc cmd /c D:\temp\testsetp.cmd
PAExec v1.26 - Execute Programs Remotely
Copyright (c) 2012-2013 Power Admin LLC
Connecting to otherpc...
Starting PAExec service on otherpc...
Enter the ip: 192.168.1.1
Enter the sub: 255.255.255.0
192.168.1.1 subnet mask 255.255.255.0
cmd returned 0
PAExec returning exit code 0