Batch file and perl

I have created a windows batch file to run a bash with perl commands in it:

 @echo off

C:
chdir C:\cygwin\bin\

bash --login -c "./windows_annovar.pl"
exit 0 

In the pl file attached the menu opens and the user makes a selection and cygwin closes. There are error messages on the screen but it closes too quickly to see them. How can I pause the batch file and keep it from closing so I can see the messages and being troubleshooting? Thank you :).

  1. This is an MS-DOS question and is more appropriate in this forum.
  2. I think it would be more convenient to directly run the perl program rather than wrapping it in a batch script. Not sure if you have a specific constraint for doing it this way.
  3. If you do want to use it, look at the pause command.

I will move the post and look into pause. Thank you :).

I have created a windows batch file to run a bash with perl commands in it:

 @echo off

C:
chdir C:\cygwin\bin\

bash --login -c "./windows_annovar.pl"
exit 0 

In the pl file attached the menu opens and the user makes a selection and cygwin closes. There are error messages on the screen but it closes too quickly to see them. How can I pause the batch file and keep it from closing so I can see the messages and being troubleshooting? Thank you :).

Merged the 2 threads...

You're going about this all wrong. :slight_smile:
The files you have attached

  • windows_annovar.sh
  • windows_annovar.pl

are the same file. You can't just rename files and expect them to run with different interpreters.

Line 117  windows_annovar.sh

    cd 'C:\Users\cmccabe\Desktop\annovar'
              $( perl table_annovar.pl ${id}_matched.avinput humandb/ -buildver ... blah blah blah)

This is calling perl table_annovar.pl to access a database (humandb) I think. Do you have all those perl files installed?? If so, perl needs to know where to find them. The full path to the folder that contains them should be in PATH as well as the full path to the perl modules.

PATH belongs in windows_annovar.sh...not this one. Actually, it belongs in the shell environment.
Get rid of this file.

windows_annovar.pl
#!/bin/bash

PATH="C:\\cygwin\\bin\perl.exe:${PATH}"
...
...
 @echo off

C:
chdir C:\cygwin\bin\

bash --login -c "./windows_annovar.sh"
exit 0 

Cygwin opens and closes quickly. The sh file is attached and in the file there are cd commands that contain the humandb. If I run it from the command line using

 bash ~/newbatch.sh 

it runs fine. Since I am using windows I altered that file a bit and would like to have a user just double click on the bat file to run the program. Thank you :).

New batch file with the same result:

Path to cygwin exe is the first line
path to bash.exe with path to shell in the second line.

 set PATH=C:\cygwin\bin;%PATH%
    c:\cygwin\bin\bash.exe C:\cygwin\home\cmccabe\windows_annovar.sh 

Cygwin opens and closes quickly. The sh file is attached in the previous post. Any suggestions? Thank you :).

I placed a pause in the script and here is the error before cygwin closes:

C:\Users\cmccabe\Desktop>set PATH=C:\cygwin\bin\cygwin.exe;C:\Windows\system32;C
:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C
:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x86;C:\Program Files (x86)\Intel\
OpenCL SDK\2.0\bin\x64;C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Bin
n\VSShell\Common7\IDE\;C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Bin
n\;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files (x86)\
Microsoft SQL Server\100\DTS\Binn\

C:\Users\cmccabe\Desktop>c:\cygwin\bin\bash.exe C:\cygwin\home\cmccabe\windows_a
nnovar.sh
Press [Enter] key to continue... 

Any suggestions for why this isn't working, I am at a loss. Thank you :).

When I use the following batch file the menu displays, but when a selection is made cygwin closes quickly.

 @echo off

C:
chdir C:\cygwin\bin\

bash --login -c "./windows_annovar.pl"
exit 0 

I attached the .pl as well. Thank you :).

Did you try to remove the "exit" from your menu point 6, or at least put a "sleep 5" in front of it?

The batch below seems to execute:

 set PATH=C:\cygwin\bin\;%PATH%
    c:\cygwin\bin\bash.exe c:\cygwin\home\cmccabe\newbatch.sh 

I attached the newbatch.sh, and here is a screenshot:

  
C:\Users\cmccabe\Desktop>set PATH=C:\cygwin\bin\;C:\Windows\system32;C:\Windows;
C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program
Files (x86)\Intel\OpenCL SDK\2.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK
\2.0\bin\x64;C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\
Common7\IDE\;C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;C:\Prog
ram Files\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files (x86)\Microsoft
SQL Server\100\DTS\Binn\
C:\Users\cmccabe\Desktop>c:\cygwin\bin\bash.exe c:\cygwin\home\cmccabe\newbatch.
sh
 MENU
    ==================================

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

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

Why is the text before MENU appearing and how do I get rid of it or hide it? Thank you :).

Looks like it's "logging" your expanded set PATH command. Did you set sth. like bash's -v option's windows equivalent?

I'm not sure how to do that.

 set PATH=C:\cygwin\bin\;%PATH%
    c:\cygwin\bin\bash.exe c:\cygwin\home\cmccabe\newbatch.sh 

to maybe

 set PATH=%PATH%;C:\cygwin\bin\;%PATH%
    c:\cygwin\bin\bash.exe c:\cygwin\home\cmccabe\newbatch.sh 

Thank you :).

I vaguely remember there's a character in DOS that you can prepend to a command line to suppress its output... maybe it's @?

1 Like

You are correct

 @set or @echo off 

can be used. Thank you very much for all of your help :).