PDA

View Full Version : [SOLVED] call shell and execute in cygwin using excel vba



cmccabe1
08-23-2016, 06:44 AM
I am trying to run a bash script in cygwin using an excel 2010 vba. In the code below I am getting a windows can not find "c:\cygwin\bin\bash.exe c:\cygwin\home\get_all_qc.sh", but that is the path to cygwin and the .sh. I have also tried "c:\cygwin\bin\bash.exe /cygwin/home/get_all_qc.sh" and got the same error. Basically what the script does is parse the 4 files in the directory and output the resutls to stdio which is read qMsg and displayed on sceen. The bash runs perfect in cygwin I am just not able to call it. Thank you :).

VBA


' LIST SCORES '
Dim qMsg As String


ChDrive "C"
ChDir "C:\aCGH"


Set objShell = CreateObject("Shell.Application")
qMsg = objShell.ShellExecute "c:\cygwin\bin\bash.exe c:\cygwin\home\get_all_qc.sh"




MsgBox "These are the qc scores: " & vbNewLine + qMsg

snb
08-23-2016, 08:16 AM
What happens with:


sub tst()
msgbox dir("c:\cygwin\bin\bash.exe")
msgbox dir("c:\cygwin\home\get_all_qc.sh")

shell "c:\cygwin\bin\bash.exe c:\cygwin\home\get_all_qc.sh"
end sub

cmccabe1
08-23-2016, 08:56 AM
A message box displays bash.exe, then in another message box get_all_qc.sh is displayed. So I think the shell will execute but thee output is not displayed. Thank you :).

snb
08-23-2016, 09:23 AM
So use:


Sub M_snb()
msgbox createobject("wscript.shell).exec("c:\cygwin\bin\bash.exe c:\cygwin\home\get_all_qc.sh").stdout.readall
End Sub

cmccabe1
08-23-2016, 09:50 AM
Thank you very much :).