Perl command error

In the attached file I get this error. Thank you :).

 C:\cygwin\home\cmccabe\windows_annovar.sh: line 117: perl: command not found 

You can't use a shebang such as "#!/bin/bash" in Windows. It just doesn't work that way. you need to look at how to write perl code for windows. You need to run perl from a .bat file that calls the perl executable directly and passes in the perl script as an argument to the perl executable.

String found where operator expected at C:\cygwin\home\cmccabe\windows_annovar.sh line 16, near "case "$menu_choice""
        (Do you need to predeclare case?)
Number found where operator expected at C:\cygwin\home\cmccabe\windows_annovar.sh line 17, near "1"
        (Missing semicolon on previous line?)
Bareword found where operator expected at C:\cygwin\home\cmccabe\windows_annovar.sh line 17, near ") match"
        (Missing operator before match?)
Bareword found where operator expected at C:\cygwin\home\cmccabe\windows_annovar.sh line 18, near ") sanger"
        (Missing operator before sanger?)
Bareword found where operator expected at C:\cygwin\home\cmccabe\windows_annovar.sh line 19, near ") batch"
        (Missing operator before batch?)
Bareword found where operator expected at C:\cygwin\home\cmccabe\windows_annovar.sh line 20, near ") individual"
        (Missing operator before individual?)
Bareword found where operator expected at C:\cygwin\home\cmccabe\windows_annovar.sh line 21, near ") supplemental"
        (Missing operator before supplemental?)
syntax error at C:\cygwin\home\cmccabe\windows_annovar.sh line 3, near ") {"
Missing comma after first argument to read function at C:\cygwin\home\cmccabe\windows_annovar.sh line 16, near "case "$menu_choice""
syntax error at C:\cygwin\home\cmccabe\windows_annovar.sh line 16, near "case "$menu_choice""
syntax error at C:\cygwin\home\cmccabe\windows_annovar.sh line 18, near "2) "
syntax error at C:\cygwin\home\cmccabe\windows_annovar.sh line 19, near "3) "
syntax error at C:\cygwin\home\cmccabe\windows_annovar.sh line 20, near "4) "
syntax error at C:\cygwin\home\cmccabe\windows_annovar.sh line 21, near "5) "
syntax error at C:\cygwin\home\cmccabe\windows_annovar.sh line 22, near "6) "
syntax error at C:\cygwin\home\cmccabe\windows_annovar.sh line 23, near "*) printf"
syntax error at C:\cygwin\home\cmccabe\windows_annovar.sh line 25, near "}"
C:\cygwin\home\cmccabe\windows_annovar.sh has too many errors.

I am not sure where to go. Thank you :).

You have to run it with perl commandname . Windows doesn't know or care what the #! line is.

Since it is not a bourne shell file, you shouldn't name it sh either. .pl would be more traditional for perl scripts.

I am trying to use VB in excel to call and execute the .sh file:

VB

 
Private Sub CommandButton1_Click()
    Dim cmd As String
    Dim ret As Double
    Dim WshShell As Object
    Dim plink_object As Object
    ' Run Linux Commands
    Set WshShell = CreateObject("WScript.Shell")
    On Error Resume Next
    Set plink_object = WshShell.Run("C:\cygwin\bin\mintty.exe C:\cygwin\home\cmccabe\windows_annovar.sh 66 ""50602_15:56:31_15:56:11_15:56:21;50602_15:57:07_15:56:47_15:56:57""", 1)
    On Error GoTo 0
End Sub 

As of know it errors on the perl commands:

 C:\cygwin\home\cmccabe\windows_annovar.sh: line 117: perl: command not found 

As a bash it runs fine as is but windows doesent seem to like it. I am not familiar enough with windows and perl.... linux seems much nicier. Thanks :).

For the third time -- it is not an sh file. You should be running it in perl because it is perl and not shell.

Running it in shell instead of perl will cause the problems you have seen, because the shell does not understand the perl code when running it in shell instead of perl.

The way to run it is to use perl instead of shell, so it runs using perl, which understands perl programs.

... mintty.exe perl script.sh

VB

 Private Sub CommandButton1_Click()
    Dim cmd As String
    Dim ret As Double
    Dim WshShell As Object
    Dim plink_object As Object
    ' Run Linux Commands
    Set WshShell = CreateObject("WScript.Shell")
    On Error Resume Next
    Set plink_object = WshShell.Run("C:\cygwin\bin\mintty.exe C:\cygwin\home\cmccabe\windows_annovar.pl 66 ""50602_15:56:31_15:56:11_15:56:21;50602_15:57:07_15:56:47_15:56:57""", 1)
    On Error GoTo 0
End Sub 
 
C:\cygwin\home\cmccabe\windows_annovar.pl: line 36: perl: command not found 

perl code:

 match() {
    printf "\n\n"
    printf "DEBUG INFO: VALUE OF \$id: %s, VALUE OF \$panel: %s\n" $id $panel
    printf "What is the id of the patient to be matched  : "; read id
    printf "What panel: "; read panel
    [ -z "$id" ] && printf "\n No ID supplied. Leaving match function." && sleep 2 && menu
    [ "$id" = "end" ] && printf "\n Leaving match function." && sleep 2 && menu
    cd 'C:\Users\cmccabe\Desktop\annovar'
    OMR=Output_Mutation_Report
               perl -aF/\\t/ -lne 'BEGIN{%m=map{chomp;s/\cM|\cJ//g;$p=join("\t",(split/\t/)[4,5]);($p,$_)} <>;$m{"#CHROM\tINFO"}=$m{"Chr\tSegment Position"}};/SEGPOS=(\d+)/ || /\t(INFO)\t/ or next;$p=$F[0]."\t".$1;exists $m{$p} and print join("\t",$_,$m{$p})' ${id}_${panel}_${OMR}.txt < ${id}_${panel}_${OMR}_Filtered.vcf > ${id}_matched.vcf
    convert 

from the perl code I removed the $( ). Thank you :).

Well... Do you have perl installed? Where is it installed? Is it in PATH?

I have perl installed here:

 C:\cygwin\bin\perl.exe 

So in the VB do I need to change the

 Set plink_object = WshShell.Run("C:\cygwin\bin\mintty.exe C:\cygwin\home\cmccabe\windows_annovar.pl 66 ""50602_15:56:31_15:56:11_15:56:21;50602_15:57:07_15:56:47_15:56:57""", 1)
    On Error GoTo 0
End Sub 

to

 Set plink_object = WshShell.Run("C:\cygwin\bin\perl.exe C:\cygwin\home\cmccabe\windows_annovar.pl 66 ""50602_15:56:31_15:56:11_15:56:21;50602_15:57:07_15:56:47_15:56:57""", 1)
    On Error GoTo 0
End Sub 

Thank you :).

Yes, if it is a perl script. You run shell code using shell; you run perl code using perl.

Wont that cause the bash not to run? Do I need to include both in the VB??

 Set plink_object = WshShell.Run("C:\cygwin\bin\mintty.exe C:\cygwin\bin\perl.exe C:\cygwin\home\cmccabe\windows_annovar.pl 66 ""50602_15:56:31_15:56:11_15:56:21;50602_15:57:07_15:56:47_15:56:57""", 1) 

Thank you :).

What bash?

If I run the script from the command line using:

 bash ~/windows_annovar.pl 

the menu options work but the perl commands do no run.

If I use VB:

 Private Sub CommandButton1_Click()
    Dim cmd As String
    Dim ret As Double
    Dim WshShell As Object
    Dim plink_object As Object
    ' Run Linux Commands
    Set WshShell = CreateObject("WScript.Shell")
    On Error Resume Next
    Set plink_object = WshShell.Run("C:\cygwin\bin\perl.exe C:\cygwin\home\cmccabe\windows_annovar.pl 66 ""50602_15:56:31_15:56:11_15:56:21;50602_15:57:07_15:56:47_15:56:57""", 1)
    On Error GoTo 0
End Sub 

The cygwin terminal opens and closes right away.

VB:

 Private Sub CommandButton1_Click()
    Dim cmd As String
    Dim ret As Double
    Dim WshShell As Object
    Dim plink_object As Object
    ' Run Linux Commands
    Set WshShell = CreateObject("WScript.Shell")
    On Error Resume Next
    Set plink_object = WshShell.Run("C:\cygwin\bin\mintty.exe C:\cygwin\home\cmccabe\windows_annovar.pl 66 ""50602_15:56:31_15:56:11_15:56:21;50602_15:57:07_15:56:47_15:56:57""", 1)
    On Error GoTo 0
End Sub 

The menu runs

 
Welcome to annovar, please make a selection
==================================

1 Match patient
2 Sanger analysis
3 Batch analysis
4 Individual analysis
5 Supplemental analysis
6 Exit

==================================
Your choice: 1

DEBUG INFO: VALUE OF $id: , VALUE OF $panel:
What is the id of the patient to be matched : H64548
What panel: Marfan20

, but the perl commands do not.

 
C:\cygwin\home\cmccabe\windows_annovar.pl: line 36: perl: command not found 

There seems to be something that the VB needs in order to make both the menu shell and perl work or is there a better way? Thank you :).

Then the code you have been showing is not the code you have been running.

Add Perl to your PATH or use an absolute path.

The file I am using for

 bash ~/newbatch.sh 

is attached.

I made some modifications to it in hopes off getting it to run using VB and windows.

Below is what I have tried:

1. removed the #!/bin/bash with #!C:\cygwin\bin\perl.exe
2. renamed the sh file to a pl
3. removed the $( ) from the perl commands
4. adjusted the VB parameters with the absolute path to perl and referenced the .pl
Set plink_object = WshShell.Run("C:\cygwin\bin\perl.exe C:\cygwin\home\cmccabe\windows_annovar.pl 66 ""50602_15:56:31_15:56:11_15:56:21;50602_15:57:07_15:56:47_15:56:57""", 1) 

Thank you :).

1) It is a bash script. You want it to run in bash. Running it in perl will not work. Also -- the #! line is ignored anyway.

2) Neither cygwin nor Windows care what the file is named in this case. I suggested renaming it to pl since it apparently contained perl code, but I had been misled.

3) Yes, by all means remove the $( ) from the perl commands. They do not belong there and will cause syntax errors or worse.

4) I made that suggestion when I thought it was a perl script. Now that I can see the contents of the perl script, I can see that it is not.

So, I suggest fixing your PATH so perl can run:

#!...

PATH="c:\\cygwin\\bin:${PATH}"

...

perl ...
1 Like

I added the Path to the script and the bash seems to run, but when it gets to the perl commands cygwin closes, the pl is attached. Thank you :).

The VB that calls the .pl is:
VB

 Private Sub CommandButton1_Click()
    Dim cmd As String
    Dim ret As Double
    Dim WshShell As Object
    Dim plink_object As Object

    ' Run Linux Commands
    Set WshShell = CreateObject("WScript.Shell")
    On Error Resume Next
    Set plink_object = WshShell.Run("C:\cygwin\bin\mintty.exe C:\cygwin\home\cmccabe\windows_annovar.pl 66 ""50602_15:56:31_15:56:11_15:56:21;50602_15:57:07_15:56:47_15:56:57""", 1)
    On Error GoTo 0
End Sub 

I am going to start a new thread as I created a bat file that references the pl file. Thank you for your help :).