Accessing Windows 10 bash through Shell

  1. ‹ Older
  2. 10 months ago

    Michel B

    6 Jan 2017 Pre-Release Testers, Xojo Pro

    BTW the bash implementation in PowerShell seems much better.

  3. @Kem T So now the question is, can we access a 64-bit command processor from a 32-bit app?

    http://stackoverflow.com/questions/27090734/how-to-run-a-batch-file-in-64-bit-mode-from-a-batch-file-in-32-bit-mode

  4. Kem T

    6 Jan 2017 Pre-Release Testers, Xojo Pro New York

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

  5. Eugene D

    6 Jan 2017 Pre-Release Testers, Xojo Pro Canada scispec.ca

    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

  6. Kem T

    7 Jan 2017 Pre-Release Testers, Xojo Pro New York

    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?

  7. Eugene D

    7 Jan 2017 Pre-Release Testers, Xojo Pro Canada scispec.ca
    Edited 10 months ago by Eugene D

    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:

    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

    The test.txt file has the following information after running the program:

    Volume in drive C is Windows
     Volume Serial Number is 52C3-8219
    
     Directory of C:\Users\eugen\Desktop\new\Bash
    
    01/07/2017  09:39 AM    <DIR>          .
    01/07/2017  09:39 AM    <DIR>          ..
    01/06/2017  11:02 PM            53,280 BashShell.xojo_binary_project
    01/07/2017  09:39 AM    <DIR>          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

    Theoretically, something like this should work, but doesn’t:

    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

    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

  8. Kem T

    7 Jan 2017 Pre-Release Testers, Xojo Pro New York

    Thanks Eugene, I might end up trying something like this.

    It's "Kem", btw, even if auto-correct disagrees. :)

  9. Eugene D

    7 Jan 2017 Pre-Release Testers, Xojo Pro Canada scispec.ca

    @Kem T 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.

  10. 9 months ago

    Eugene D

    7 Jan 2017 Pre-Release Testers, Xojo Pro Canada scispec.ca

    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?

  11. Kem T

    7 Jan 2017 Pre-Release Testers, Xojo Pro New York

    I'll give that a try and let you know, thanks.

or Sign Up to reply!