1

I'm using bash on Ubuntu on Windows. I navigate to a folder and from there I'd like to open a file in a Windows program.

For example: After entering

cd \mnt\c\Users\myusername\Desktop
notepad index.php

I'd like Notepad on Windows to open the file index.php from my desktop.

Is this possible? If not, is it possible to make a program that would make it possible? How to go about it?

4 Answers 4

2

Nowadays you can invoke Windows applications from WSL, both from linux scripts and the console.

  • Starting from Windows 10 build 17063+, both linux and windows may share environment variables.
  • By default, Windows shares the PATH. If the notepad is in the windows path, you can run it in the Linux invoking the program in the command line.
  • You may control which variables are shared among Windows and Linux. There is a WSLENV variable that defines how the variables are shared.

Note that modifying linux files from Windows may produce errors updating the permissions and other metadata. The file permissions from Linux are stored as Streams (metadata) in the NTFS files. Windows programs may overwrite (or damage) that data without noticed it.

  • Microsoft recommends to store shared files in the Windows filesystem and, for instance, create symbolic links from linux.
  • You may check solutions and workarounds in the WSL issue report
1

It's not possible at the moment, but this is the most requested feature on UserVoice.

Reaction from Microsoft:

We hear ya – this is a common request and one we’ll be exploring for future releases.

1

This might be possible:

  1. Define an alias or a function in your ~/.bash_aliases or ~/.bashrc, to a command name like win or windows.

  2. Typing our new command would create a text file in some folder accessible by Windows.

  3. Create a batch script that runs in the background. This script would execute the command in the text file (the arguments of our newly created command would redirect to that file) whenever it is created and then delete it.

I don't have the update, so I can't provide the scripts at the moment.

0

I don't think that this is possible.
Bash on Ubuntu on Windows is not a Windows Command Line so it can't recognize Windows commands.
Try nano index.php instead.

If you want a GUI though, you can install and run XMing Server on Windows, export DISPLAY=localhost:0.0, and install gedit. Like that it can execute with a GUI. But it still won't be notepad.exe. That's impossible until we can find access to the subsystem's files.

Another way is to copy the file to your C drive and access it from Windows. To do that try something like cp index.php /mnt/c

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .