BTW the bash implementation in PowerShell seems much better.
[quote=308103:@Kem Tekinay]
So now the question is, can we access a 64-bit command processor from a 32-bit app?[/quote]
Brilliant. This gets me closer in that I now get the same “Error: 0x80070057” as when I run in 64-bit mode directly. And I get the result back as UTF-16, same as in 64-bit mode. Now I just have to figure out what that’s about…
Hi Ken,
Its not perfect, and running this code will open bash in a bash window. Put this code in a button action event.
Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (hWnd As UInt32, lpszOp As CString, lpszFile As CString, lpszParams As CString, LpszDir As CString, FsShowCmd As UInt32) As UInt32
call ShellExecute 0, "open", "C:\\Windows\\Sysnative\\bash.exe", "","", 1
Or Xojo Shell can run with the following code:
Dim MyShell as new Shell
MyShell.Execute("C:\\Windows\\Sysnative\\bash.exe")
I haven’t figured out how to send a command such as ‘ls’ yet
Thanks Eugene.
The trouble is, I need to get output back from bash, same as I would on a Mac or Linux, but I don’t think either of those solutions would allow that. Or am I wrong?
Hello Ken,
The way that information can be retrieved from the command prompt and placed in a text file is shown in the below example that requests the directory and places the contents of the directory in a file on my computers desktop in a test.txt file:
[code]Declare Function ShellExecute Lib “shell32.dll” Alias “ShellExecuteA” (hWnd As UInt32, lpszOp As CString, lpszFile As CString, lpszParams As CString, LpszDir As CString, FsShowCmd As UInt32) As UInt32
call ShellExecute 0, “open”, “cmd.exe”, “/C dir > C:\Users\eugen\Desktop\test.txt” , nil, 1[/code]
The test.txt file has the following information after running the program:
[code]Volume in drive C is Windows
Volume Serial Number is 52C3-8219
Directory of C:\Users\eugen\Desktop
ew\Bash
01/07/2017 09:39 AM .
01/07/2017 09:39 AM …
01/06/2017 11:02 PM 53,280 BashShell.xojo_binary_project
01/07/2017 09:39 AM DebugMy Application
01/06/2017 09:55 PM 482 mystring
2 File(s) 53,762 bytes
3 Dir(s) 412,531,548,160 bytes free[/code]
Theoretically, something like this should work, but doesnt:
[code]Declare Function ShellExecute Lib “shell32.dll” Alias “ShellExecuteA” (hWnd As UInt32, lpszOp As CString, lpszFile As CString, lpszParams As CString, LpszDir As CString, FsShowCmd As UInt32) As UInt32
call ShellExecute 0, “open”, “C:\Windows\Sysnative\bash.exe”, “/C ls > C:\Users\eugen\Desktop\test.txt” , nil, 1[/code]
Windows has these bash commands in beta mode, and the hope is that this functionality will be implemented before the beta programme is finished. I am just crossing my fingers that this happens.
Edit: Changing spacing to make it look nicer
Thanks Eugene, I might end up trying something like this.
It’s “Kem”, btw, even if auto-correct disagrees.
My apologies Kem. I wrote the response in Word and it ‘autocorrected’ me. I should have caught the mistake.
Hi Kem,
I have a working solution.
ls > trial.txt
In bash, this takes a list of the directory and the contents are placed in the file called trial.txt - works great.
On the Windows Bash website at: Command Reference, the bash -c “ls > trial.txt” command should work. The code was modified for Xojo and here is what I have:
Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (hWnd As UInt32, lpszOp As CString, lpszFile As CString, lpszParams As CString, LpszDir As CString, FsShowCmd As UInt32) As UInt32
Dim myresult as Uint32
myresult = ShellExecute(Window1.Handle, "open", "C:\\Windows\\Sysnative\\bash.exe"," -c ""ls > trial.txt"" ", "", 1)
MsgBox "myresult = " + myresult.ToText
The returned value is 42 - any value above 32 means that the ShellExecute command worked properly. Beside the xojo_binary_project file appears the name of the list contents which is trial.txt.
On my computer the output of the trial.txt file is shown below:
BashShell.xojo_binary_project
DebugMy Application
trial.txt
Does this work for you?
I’ll give that a try and let you know, thanks.