8

Most systems provide an open command (alternately known as start, cygstart, xdg-open etc.) which opens a file in the desktop environment's "default" application, whatever that is.

For example, from Powershell when I enter:

PS> start form.pdf

The document pops open in Edge.

Can Bash-on-Ubuntu-on-Windows do this?

16

Since the Windows Linux interop started working you can now call:

cmd.exe /C start <file>
  • Works for me for relative paths, for absolute paths I wrote a script to substitute /mnt/c by c: ... | sed 's/\/mnt\/\(.\)/\1:/1' | xargs cmd.exe /C start – Michael Oct 4 '17 at 20:58
  • 1
    Nice solution. We can also access files on the Linux filesystem using info from superuser.com/q/1110974/66714. Something like cmd.exe /c start "%localappdata%/lxss/$(readlink -f $some_relative_path)" Now we're cooking with fire! – Cheezmeister Oct 8 '17 at 0:45
2

This depends on whether you want to A) launch a linux program inside WSL or B) you want to launch a windows program from a bash shell prompt.

If B) then yes if you install cygwin/bash. For example install git for windows and you have a system running under windows with bash. Then you can just run start, actually it is included as a script:

$ cat /usr/bin/start
#!/usr/bin/env bash
# Copyright (C) 2014, Alexey Pavlov
#   mailto:alexpux@gmail.com
# This file is part of Minimal SYStem version 2.
#   https://sourceforge.net/p/msys2/wiki/MSYS2%20installation/
# File: start

cmd //c start "${@//&/^&}"

If A) then it gets much more difficult especially if you want to launch a linux program to display a .pdf in a GUI window. Note that Windows knows to associate a default application to open a pdf file but WSL doesn't have the information. So even if you did get a Desktop running under WSL you would need to associate a linux GUI app to open the pdf.

Note to clarify, within WSL you execute linux executables not windows executables:

(WSL):~# file /bin/gzip
/bin/gzip: ELF 64-bit LSB  executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=68cc3c090405cf6d40e97d2ff58085fd26940602, stripped

(WSL):~# file /mnt/c/Program\ Files/Internet\ Explorer/iexplore.exe
 /mnt/c/Program Files/Internet Explorer/iexplore.exe: PE32+ executable (GUI) x86-64, for MS Windows

(WSL):~# /mnt/c/Program\ Files/Internet\ Explorer/iexplore.exe
 bash: /mnt/c/Program Files/Internet Explorer/iexplore.exe: cannot execute binary file: Exec format error
-2

WSL got Windows-Linux interop working in october, so I guess that you should be able to use Windows' start directly in Bash, just as you did in Powershell.
Just call it with start.exe

  • 1
    Doesn't work for me. Perhaps it's because I'm actually using zsh. Does this work for you? – Cheezmeister Jan 4 '17 at 16:50
  • 1
    no such thing as start.exe – Steven Penny Jan 1 '18 at 21:33

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.