Batch file input issues on remote computer

2

1

I made a batch file that takes various inputs and then uses them in the commands ahead. This script works fine on my computer but when I put this script on another computer and use PsExec.exe to remotely execute this file... it doesn't work like it was working... The batch file runs fine if executed on the same computer... this error only occurs on network.

It's supposed to take to inputs and use them like..

set /p ip=Enter the ip: [The user enters 192.168.1.1]
set /p sub=Enter the sub: [The user enters 255.255.255.0]
echo %ip% sub net mask %sub%

It should echo

192.168.1.1 sub net mask 255.255.255.0

instead it echos

1 sub net mask 2

it doesn't even stop to take the other input. In simpler words its only taking the first character of anything that is entered. Any help?

Kunwar

Posted 2015-11-29T14:27:42.813

Reputation: 323

Answers

2

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 testsetp.cmd

@echo off

set /p "ip=Enter the ip: "
set /p "sub=Enter the sub: "

echo %ip% subnet mask %sub%

outputs

C:\etc>paexec \\otherpc cmd /c D:\temp\testsetp.cmd

PAExec v1.26 - Execute Programs Remotely
Copyright (c) 2012-2013 Power Admin LLC
www.poweradmin.com/PAExec


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

dxiv

Posted 2015-11-29T14:27:42.813

Reputation: 1 784