2

I am using Psexec to run a remote batch file. I pass input to psexec and redirect it to the remote batch file which seeks a filename as its input. However while redirecting, the file name becomes a garbage as @##&#* which means actual file name is not passed to batch file which the user gives. can anyone tell what might be the reason for this.

pause
cd c:
set /P INPUT=Type input: %=%
echo Your input was: %INPUT%
copy %INPUT% \\remotemachineip\C$ && c:\psexec \\machineip cmd /k "c:\batchfile.bat arg1 < %INPUT% & del %INPUT%"  -e -c -f -i
pause
sandeep
  • 31
  • 5
  • I've removed the extra tags as the question has nothing to do with SQL server. Keep tags specific as someone who knows about psexec might be put off by the odd sql-server tags. – Stephen Turner Nov 21 '11 at 16:41
  • I am working in sql server so i thought anyone who has run some sql scripts would have used this way. so added the tag. – sandeep Nov 21 '11 at 17:21

1 Answers1

1
pause
cd c:
set /P INPUT=Type input: %=%
echo Your input was: %INPUT%

copy %INPUT% \\remotemachineip\C$ && c:\psexec \\machineip cmd /k c:\batchfile.bat %INPUT% & del %INPUT%  -c -f -i
pause

the remote batch file which seeks input from the above batch file commands on the local machine. so %1(below command) is replaced by the %INPUT%(the second argument in the cmd.exe in the above code content) which the user enters and the sqlcmd command will be executed. so the input which the user passes in the above batch file will be successfully redirected to the below batch file(content) and the command(sqlcmd below) in it will be successfully executed.

SQLCMD  -Sservername -d(databasename) -iC:LINKEDSERVER.sql -v filename="%1"

for e.g if I give %INPUT% as c:\inputfile.xls it will be redirected to SQLCMD command in place of %1, so it executes it as--

SQLCMD  -Sservername -d(databasename) -iC:LINKEDSERVER.sql -v filename="c:\inputfile.xls"
sandeep
  • 31
  • 5