Accessing Windows 10 bash through Shell

  1. ‹ Older
  2. 10 months ago

    Sascha M

    5 Jan 2017 Europe (Germany)
    Edited 10 months ago by Sascha M

    maybe you write a run.vbe with this and try to shell.execute this :) cant test it by my self cause i have linux sub only on my NAS for nextcloud

  3. Kem T

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

    Thanks, I'll keep experimenting.

  4. Edited 10 months ago by Norman P

    Try executing cmd.exe and then running your bash script

    Shell ≠ cmd.exe instance

  5. Kem T

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

    Would I need to do this though an Interactive Shell, or is there another way? I tried cmd.exe /C /path/to/bash etc with the same result.

  6. probably an interactive shell

  7. Kem T

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

    Same result, unfortunately.

  8. David M

    5 Jan 2017 Edinburgh, UK

    I use the bash shell on Windows to back up my VPS using rsync. A batch file called "Run backup script.bat" contains the following:

    bash -c /mnt/d/VPS-Backup/BackupScript.sh
    
    pause

    And (sorry, no solution here!) I've run into what I suspect is a related problem. What I'd like to do is run the batch file using Windows' Task Scheduler so that I can have regular unattended backups. But when launched from Task Scheduler it just plain doesn't run - same as you're getting. I spent a lot of time Googling around for possible solutions for this and came up blank. The best workaround I came up with was to use Task Scheduler to run the script when I log on to the computer. That works.

    As far as I can see, there's something that's available when the script is launched by a user that isn't available when it's launched from elsewhere, even if the same user credentials are used.

    Would love to find a solution to this - right now I've got my fingers crossed for the next release of Windows 10, allegedly due in March/April.

  9. Michel B

    6 Jan 2017 Pre-Release Testers, Xojo Pro

    When I installed bash, it required to create a login and password. Would it be possible that calling bash from another place than Command Prompt did require login in ?

  10. David M

    6 Jan 2017 Edinburgh, UK

    That's a good point, maybe it is something to do with the "Default UNIX User Account". There's more info on that here: https://msdn.microsoft.com/en-us/commandline/wsl/user_support .

    I'm away from my main Windows 10 machine at the moment, so can't test, but Kem - did you try Sasha's suggestion of right-clicking on your Xojo app and choosing "Run as Administrator" to run it with elevated permissions?

  11. Kem T

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

    @Paul L and I did some digging and may have come up with a reason, but not a solution. bash requires 64-bit, but Shell in a 32-bit app is in ... well, 32-bit, and can't access bash. Running as 64-bit gets further but we didn't pursue that very far.

    So now the question is, can we access a 64-bit command processor from a 32-bit app?

  12. Michel B

    6 Jan 2017 Pre-Release Testers, Xojo Pro

    BTW the bash implementation in PowerShell seems much better.

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

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

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

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

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

  18. 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. :)

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

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

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