Run Bash from Windows icon?

Is it possible to run a bash using a by creating an icon or shortcut in windows 7? Everything seems to be for unix or linux and unfortunately my institution is windows.

For example, run

 bash ~/newbatch.sh 

by clicking on an icon on a users desktop. Cygwin will be installed as well. Thank you :).

Would being able to run .sh files suit your purposes? bash - How can I associate .sh files with Cygwin? - Stack Overflow

1 Like

I will give it a try. Thank you :).

I can't add or change software at my institution. Is it possible to execute a bash using VB in excel?

Maybe a button that the user clicks would call and execute the bash? Thank you :).

---------- Post updated at 01:00 PM ---------- Previous update was at 10:25 AM ----------

I normally run a bash script in cygwin terminal using bash ~/annovar.sh. I am trying to avoid scripting and am using the VB below to call and execute a bash script. This is on a windows machine in excel 2010.

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 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 

the cygwin terminal starts but says: annovar.sh: No such file or directory

annovar.sh is in C:\cygwin\bin\

should it be somewhere else? and what does 66 ""50602_15:56:31_15:56:11_15:56:21;50602_15:57:07_15:56:47_15:56:57""", 1) refer to? Thank you :).

Tell it the path to the script too.

Not sure why:

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 

The above code worked great, but now cygwin opens and then closes right away. Is there a better way? Thanks.

If you are working with Windows servers then you should find Windows based solutions. I had to write scripts for Windows 2000 servers and I used Cygwin and Bash, but I put everything into a .bat file making sure to add the C:\Cygwin64\bin or C:\Cygwin\bin directory to my path statement. I can then write a regular .bat script, but use Cygwin tools like rsync and gzip. When you are testing and running the scripts you need to run them from the command prompt otherwise you won't see the output. You should also increase the number of rows buffered on the screen so that you can see more output.

I was talking to another developer about scripting and Windows who said that Powershell on Windows servers have all of the Unix tools, plus the .NET programming stuff. So you may want to look into Powershell. I tried looking at it, but it didn't seem accessable to me, but I have spent most of my career trying to avoid working with Windows servers. Apparently many former Digital Equipment Corp (DEC) programmers went to Microsoft after the demise of DEC and helped to build Powershell to be more Unix like. I don't know if that is true or not.

I am not familiar with bat files or how to use them with cygwin. Thank you :).

I would probably start with this link:

http://tinyurl.com/ov25zmk

Here is some untested sample code:

SET PATH=C:\Cygwin64\bin;%PATH%

tar -xvf /cygdrive/c/ExcelDatabaseFileBackups/dbbackup.tar  /cygdrive/c/ExcelDatabaseFiles/*
gzip /cygdrive/c/ExcelDatabaseFileBackups/dbbackup.tar 
rsync /cygdrive/c/ExcelDatabaseFileBackups/dbbackup.tar  //uncpath_to_server/dbbackup_share/*

you just need to learn the commands and start writing scripts.
Start with simple tasks and keep adding functionality.