Git hook pre-commit error: "command not found"
You probably want to prefix the calls to your .vbs
scripts with:
cscript yourscript.vbs
You're running a Bash/sh script from your Git hook.
Your Bash/sh implementation won't know what to do with Start-Sleep
because that's a PowerShell command. You'll need to find some Bash equivalent or shell out to PowerShell to execute that statement.
The script then tries to execute the contents of RevisionDate.vbs
and MovePDF.vbs
as Bash/sh statements rather than launch the VBScript interpreter that would normally be associated under a cmd.exe
command shell. So you need to tell your shell script how to do this, i.e., cscript yourscript.vbs
.
Paths:
Also watch those paths. Most Windows Bash/sh shell implementations won't know what C:\blah\blah
means (the \
is used as an escape character). Instead you need to use Unix-style paths. For example,
'C:\Users\Ian\desktop\Test2'
would translate to:
/c/Users/Ian/desktop/Test2
Ian Pennebaker
Updated on June 05, 2022Comments
-
Ian Pennebaker almost 2 years
I have a simple Git hook that calls some other (VBScript) scripts. The script runs correctly when I call it from the command line. However, when the hook is executed, it gives me the following error(s):
./RevisionDate.vbs: line 1: syntax error near unexpected token `(' ./RevisionDate.vbs: line 1: `Set copyFSO = CreateObject ("Scripting.FileSystemObject")' .git/hooks/pre-commit: line 8: Start-Sleep: command not found test ./MovePDF.vbs: line 1: unexpected EOF while looking for matching `'' ./MovePDF.vbs: line 6: syntax error: unexpected end of file
Here is the VBScript that gets called in the hook.
Set copyFSO = CreateObject ("Scripting.FileSystemObject") copyFSO.copyFile "C:\Users\Ian\Desktop\Test\*.pdf", "C:\Users\Ian\Desktop\Test2" copyFSO.moveFile "C:\Users\Ian\Desktop\Test\*.pdf", "C:\Users\Ian\Desktop\Temp" '------ Microsoft Excel ------- inputPrefix = cint(inputbox("Please enter two digit prefix for file you would like updated.", "File Update")) Set objExcel = CreateObject("Excel.Application") objExcel.Visible = False sFolder = "C:\Users\Ian\Desktop\Test" Set oFSO = CreateObject("Scripting.FileSystemObject") For Each oFile In oFSO.GetFolder(sFolder).Files fileName = oFile Set objWorkbook = nothing Set objSelection = nothing Set objWorksheet = nothing If UCase(oFSO.GetExtensionName(oFile.Name)) = "XLSX" Then Prefix = left(oFile.Name, 2) filePrefix = cint(Prefix) Set objWorkbook = objExcel.Workbooks.Open(fileName) Set objSelection = objExcel.Selection Set objWorksheet = objWorkbook.Worksheets(1) objExcel.DisplayAlerts = False myYear = Year(Now()) myMonth = Month(Now()) myDay = Day(Now()) myDate = myYear & "/" & myMonth & "/" & myDay myDateFile = myYear & "-" & myMonth & "-" & myDay If (filePrefix = inputPrefix) then objWorksheet.PageSetup.RightFooter = "Revision Date: " & myDate & " C" objWorkbook.Save End If fileName = Replace(oFile.Name, ".xlsx", "") saveAndCloseXlsx objWorkbook End if Next Function saveAndCloseXlsx(objWorkbook) objWorkbook.ExportAsFixedFormat xiTypePDF, "C:\Users\Ian\Desktop\Test\" & fileName objWorkbook.Close end Function '------ Microsoft Word ------- Set objWord = CreateObject("Word.Application") objWord.Visible = False sFolder = "C:\Users\Ian\Desktop\Test" Set oFSO = CreateObject("Scripting.FileSystemObject") For Each oFile In oFSO.GetFolder(sFolder).Files If UCase(oFSO.GetExtensionName(oFile.Name)) = "DOCX" Then fileName = oFile Set objDoc = objWord.Documents.Open(fileName) Set objSelection = objWord.Selection If objDoc.Bookmarks.Exists("RevisionDate") = True Then Set objRange = objDoc.Bookmarks("RevisionDate").Range myYear = Year(Now()) myMonth = Month(Now()) myDay = Day(Now()) myDate = myYear & "/" & myMonth & "/" & myDay myDateFile = myYear & "-" & myMonth & "-" & myDay Prefix = left(oFile.Name, 2) filePrefix = cint(Prefix) If (inputPrefix = filePrefix) then objRange.text = "Revision Date: " & myDate & " C" objDoc.Bookmarks.Add "RevisionDate", objRange End If wdFormatPDF = 17 SaveAndCloseDocx objDoc End If End if Next set oFSO = Nothing objWord.Quit Function SaveAndCloseDocx(objDoc) fileName = Replace(oFile.Name, ".docx", "") objDoc.SaveAs "C:\Users\Ian\Desktop\Test\" & fileName & ".pdf", wdFormatPDF objDoc.Close End Function
And finally the hook itself:
#!/bin/sh # # echo "Script Running" cd 'C:\Users\Ian\desktop\QMS_Manual' "./RevisionDate.vbs" Start-Sleep -s 30 "./MovePDF.vbs" cd 'C:\Users\Ian\desktop\Test2' pdftk *.pdf cat output ECMWC.pdf cd 'C:\Users\Ian\desktop\QMS_Manual' DeleteAllButFinal.vbs
Why does this happen? I've read it may have something to do with the
PATH
environment variable. -
Ian Pennebaker almost 9 yearsThank you for the suggestion but it did not resolve or change the error message
-
Ian Pennebaker almost 9 yearsOkay so theoretically I would have to go through the whole VBScript and convert to bash for it to run? Is there any way to run a VBScript normally?
-
Kev almost 9 years@IanPennebaker Ok, open a gitbash console then type
cscript
, hit return, and tell me what you see. -
Ian Pennebaker almost 9 years
Options: //B Batch mode: Suppresses script errors and prompts from displaying //D Enable Active Debugging //E:engine Use engine for executing script //H:CScript Changes the default script host to CScript.exe //H:WScript Changes the default script host to WScript.exe (default) //I Interactive mode (default, opposite of //B) //Job:xxxx Execute a WSF job //Logo Display logo (default) //Nologo Prevent logo display: No banner will be shown at execution time //S Save current command line options for this user
-
Ian Pennebaker almost 9 years
//T:nn Time out in seconds: Maximum time a script is permitted to run //X Execute script in debugger //U Use Unicode for redirected I/O from the console
@Kev -
Ian Pennebaker almost 9 yearsSorry, that is difficult to read. I appreciate your help. @Kev
-
Kev almost 9 years@IanPennebaker Right, what I'm saying is that you need to call the cscript interpreter from your bash script so cscript interprets and executes your
.vbs
scripts. Git's bash won't know how to do that just by specifying the name of a random script containing statements it won't understand. -
Ian Pennebaker almost 9 yearsThank you very much. You just saved me a lot of headache!
-
Kev almost 9 years@IanPennebaker you're welcome chap. :) Have also added a bit about paths in these types of bash/sh ports to Windows.