1

i am trying to run .bat file from command line , which calls a UNIX shell script, earlier it was working all fine, and suddenly now i am getting this issue when i run .bat from command line, it also comes at very specific line.

Error-:

'P" "'' is not recognized as an internal or external command,
operable program or batch file.

Bat File-:

@ECHO OFF

setlocal EnableDelayedExpansion
set n=0
for %%a in (%*) do (
   set vector[!n!]=%%a
   set /A n+=1
)


SET admPath=%vector[0]%
SET admdatatype=%vector[1]%
SET admeaimethod=%vector[2]%
SET admprefix=%vector[3]%
SET gatewayname=%vector[4]%
SET enterpriseName=%vector[5]%
SET serverName=%vector[6]%
SET serveruserId=%vector[7]%
SET serverpassword=%vector[8]%
SET userId=%vector[9]%
SET password=%vector[10]%
SET host=%vector[11]%
SET sudoUser=%vector[12]%
SET localPath=%vector[13]%
SET admFilter=%vector[14]%

echo %admPath%
echo %admdatatype%
echo %admeaimethod%
echo %admprefix%
echo %gatewayname%
echo %enterpriseName%
echo %serverName%
echo %serveruserId%
echo %serverpassword%
echo %userId%
echo %password%
echo %host%
echo %sudoUser%
echo %localPath%
echo %admFilter%


echo y | "C:\Program Files\PuTTY\plink" -ssh %userId%@%host% -pw %password% exit

"C:\Program Files\PuTTY\plink" -ssh -t %userId%@%host% -pw %password% "/opt/siebel/w44gq8sw/ExportLov.sh %admPath% %admdatatype% %admeaimethod% %admprefix% %gatewayname% %enterpriseName% %serverName% %serveruserId% %serverpassword% %admFilter% %password% %sudoUser% %localPath% " > LovExport_Status.txt 2>&1

In above code if a remove the last line, i can't see that error printed on console, but when i keep that line , i get the above mentioned error in output file.It was working all fine before, i am not getting why i am getting this issue now. Please help.

UNIX SCRIPT-:

#!/bin/bash
source ~/.profile
admPath=$1
admdatatype=$2
admeaimethod=$3
admprefix=$4
gatewayname=$5
enterpriseName=$6
serverName=$7
userId=$8
password=$9
admFilter=${10}
serverPassword=${11}
serverSudoUser=${12}
localPath=${13}

echo "$admPath"
echo "$admdatatype"
echo "$admeaimethod"
echo "$admprefix"
echo "$gatewayname"
echo "$enterpriseName"
echo "$userId"
echo "$password"
echo "$admFilter"
echo "$serverPassword"
echo "$serverSudoUser"
echo "$serverName"
echo "$localPath"

echo "$serverPassword" | sudo -S -l
sudo $serverSudoUser  <<EOF
./exportLOV.sh "$admPath" "$admdatatype" "$admeaimethod" "$admprefix" "$gatewayname" "$enterpriseName" "$serverName" "$userId" "$password" '$admFilter' "$localPath"
EOF

I have checked enviornment variable for windows, it looks good because error comes at specific line , i guess the issue is something else.

Please let me know if any other information is required.

Tushar Sharma
  • 2,297
  • 1
  • 9
  • 25
  • why do you set the `vector` variables there? simply use `%1`, `%2`... for `vector[1]`, `vector[2]`... and remove `echo off` to see where the error happens – phuclv Jan 19 '18 at 11:36
  • @Luu Vinh Phuc let me test without echo, I will update you back – Tushar Sharma Jan 19 '18 at 11:46
  • @ Lưu Vĩnh Phúc What should i check after setting echo off? – Tushar Sharma Jan 19 '18 at 12:22
  • probably you have a poison character in one of the passwords (I guess in `%serverpassword%`, as the line before with `%password%` seems to execute without error) – Stephan Jan 19 '18 at 13:44

1 Answers1

2

One of string values of the environment variables referenced on command line

"C:\Program Files\PuTTY\plink" -ssh -t %userId%@%host% -pw %password% "/opt/siebel/w44gq8sw/ExportLov.sh %admPath% %admdatatype% %admeaimethod% %admprefix% %gatewayname% %enterpriseName% %serverName% %serveruserId% %serverpassword% %admFilter% %password% %sudoUser% %localPath% " > LovExport_Status.txt 2>&1

contain & or | which have special meanings if the argument string containing this character is not enclosed in straight double quotes, see Single line with multiple commands using Windows batch file.

Argument strings containing a space or one of these characters &()[]{}^=;!'+,`~<|> must be enclosed in double quotes to get interpreted the entire argument string as literal string.

So I strongly recommend:

"C:\Program Files\PuTTY\plink" -ssh -t "%userId%@%host%" -pw "%password%" "/opt/siebel/w44gq8sw/ExportLov.sh %admPath% %admdatatype% %admeaimethod% %admprefix% %gatewayname% %enterpriseName% %serverName% %serveruserId% %serverpassword% %admFilter% %password% %sudoUser% %localPath% " > LovExport_Status.txt 2>&1

%userId%@%host% and %password% are also enclosed in double quotes.

I suppose the string value of environment variable password contains an ampersand or vertical bar and next non space character is p resulting in the error message on execution of the batch file.

The cause of the error can be seen by inserting above last line echo on and run the batch file from within a command prompt window instead of double clicking on the batch file.

I recommend also reading answer on Why is no string output with 'echo %var%' after using 'set var = text' on command line? on assigning strings to environment variables containing & or | or other characters with a special meaning on command line if not being enclosed in a double quoted string and the environment variables are referenced with expansion during preprocessing phase of Windows command interpreter before command execution instead of usage of delayed expansion.

Mofi
  • 38,783
  • 14
  • 62
  • 115