Andrew Cornford
Andrew Cornford

Reputation: 35

Why could the behavior of batch script be inconsistent on various computers?

I'm writing a batch script to automatically push and pull to git (for reasons I won't go into here).

The script works fine on my PC, but doesn't work on my colleagues computer. It gets to the part where MessageBox.exe asks if you want to commit, but on his PC I then get an error

find : yes : Cannot find the specified file or directory.

On my PC the script works just fine. We have the same OS etc, so I don't know where to start.

I know this is a very loose question, and I'm new to scripting in Windows but any hints would be great.

Thank you!

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
call %~dp0%config.bat

SET scriptPath=%~dp0
SET file=%1

echo Saving current working directory
SET cwd=%cd%

echo Loading SSH key (%SSHKey%)
START "" "%puttyLocation%pageant.exe" "%SSHKey%"

echo Moving to library directory (%libDir%)
cd /D %libDir%

echo Pulling from git....
git pull %remoteName%

echo Changing back to the original directory (%cwd%)
cd /D %cwd%
%easyPCLocation% %file%

echo Moving to library directory (%libDir%)
cd /D %libDir%

git status --porcelain
git status --porcelain > %scriptPath%temp.txt

for %%A in (%scriptPath%temp.txt) do if %%~zA==0 (
    echo.No changes to your library have been made.
) ELSE (
    echo Changes have been made to your library. Please push them to git now.
    !scriptPath!MessageBox.exe "Changes have been made to your library.     Please push them to git now.\n\nWould you like up push to git?" "Library updates detected!" YesNo Question Button1 > %scriptPath%temp2.txt
find "yes" !scriptPath!temp2.txt && (
    !scriptPath!InputBox.exe "Commit message:" "Updating git..." > !scriptPath!temp2.txt
    set /p commitMessage=<!scriptPath!temp2.txt
    echo !commitMessage!
    git add .
    git commit -a -m "!commitMessage!"
    git push
) || (
echo REMEMBER to push changes manually!!!!
    )
  del !scriptPath!temp2.txt
)
del %scriptPath%temp.txt

echo Changing back to the original directory (%cwd%)
cd /D %cwd%

endlocal

Upvotes: 0

Views: 114

Answers (1)

Magoo
Magoo

Reputation: 80023

I'd suggest that your colleague has installed cygwin so find is a completely different executable (locate-a-file.)

I'd point find explicitly by replacing it with %SystemRoot%\System32\find.exe. This bypasses cygwin if it's installed and uses Windows' version of find. If cygwin is not installed, it's safe to use this explicit definition - it's where Windows would locate the executable using its normal strategy.

Upvotes: 3

Related Questions