Accessing Windows 10 bash through Shell

  1. 11 months ago

    Kem T

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

    Is there some trick that will allow me to run bash script in Windows through the Shell or otherwise? The commands that work in the DOS prompt ("bash shellscript.sh") tells me bash is not recognized when run through Shell.

  2. Michel B

    5 Jan 2017 Pre-Release Testers, Xojo Pro

    As usual, you may need to point to bash.exe full path.

  3. Kem T

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

    I tried, didn't work.

  4. Sascha M

    5 Jan 2017 Europe (Germany)

    bash is only available if you installed linux subsystem. Then you can use this for example: bash.exe -c sudo "/etc/init.d/apache2 start"

    The example will start apache and close it immediately, cause the bash doesnt keep it open. But it should help you to start a script.

  5. Kem T

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

    Thanks Sascha, but have you tried this using the Xojo Shell? That's where I'm having trouble as the same commands that work on the DOS prompt fail in Shell with...

    'C:\Windows\System32\bash.exe' is not recognized as an internal or external command,
    operable program or batch file.
  6. Michel B

    5 Jan 2017 Pre-Release Testers, Xojo Pro

    I see the same here.

  7. Kem T

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

    I bet there is going to be some OLE way of doing this...

  8. Sascha M

    5 Jan 2017 Europe (Germany)
    Edited 11 months ago

    Try to start your app as admin. But no i dont tried in xojo, the shell got so many problems on windows with... for aexample some java comands dont work really, maybe this is a problem too.

  9. Sascha M

    5 Jan 2017 Europe (Germany)

    maybe you try it with a vbe

    set ws=wscript.createobject("wscript.shell")
    ws.run "C:\Windows\System32\bash.exe -c 'sudo /usr/sbin/sshd -D -p 2222'",0
  10. Kem T

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

    You are suggesting I run this through Shell.Execute?

  11. Sascha M

    5 Jan 2017 Europe (Germany)
    Edited 11 months ago

    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

  12. Kem T

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

    Thanks, I'll keep experimenting.

  13. Edited 11 months ago

    Try executing cmd.exe and then running your bash script

    Shell ≠ cmd.exe instance

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

  15. probably an interactive shell

  16. Kem T

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

    Same result, unfortunately.

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

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

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

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

  21. Newer ›

or Sign Up to reply!