"Couldn't find a file descriptor referring to the console" on Ubuntu bash on Windows

LinuxWindowsBashUbuntuTerminal

Linux Problem Overview


I'm new in here and it's my first post.

I have a problem with Bash on Ubuntu on Windows. If I type "open (filename)" on Mac terminal, it opens the file with the right program but if I try to use it on Windows bash, it says: "Couldn't find a file descriptor referring to the console".

I have also tried xdg-open and gnome-open but none of them works. Can someone explain how to fix the issue and how open command works?
Thanks in advance!

Linux Solutions


Solution 1 - Linux

Instead of open u can use xdg-open which does the same thing, independently of application i.e. pdf, image, etc. It will open a new virtual terminal (I have tried this on Linux)

Example:

xdg-open ~/Pictures/Wallpapers/myPic.jpg

xdg-open ~/Docs/holidays.pdf

Solution 2 - Linux

For linux, use xdg-open. open is for Mac OS. open in linux is an name alias of openvt (open virtual terminal).

To simplify it, you can append the following line to ~/.bashrc or ~/.zshrc depends on the shell you are using.

alias o="xdg-open" # o stands for open 

Then next time you can just type like the following to reduce some keyboard strokes.

o file_name.pdf

Solution 3 - Linux

That's because open is a Mac specific command, it is not available under Linux (ubuntu), Mac open can execute a file (if the file is executable), or open the file into a text editor (if it is a document or text file) or open a directory.

Solution 4 - Linux

On Linux, the open command is an alias for openvt, which runs a command in a new virtual terminal. The virtual terminals are opened by the console. The console only likes to respond to real terminals (not emulated terminals), so the console did not give the emulated terminal it's control FD. Try running your jpg, pdf, ... viewer's command directly in your terminal. (Try sudo openvt -f -s -c 7 -- echo hi in a real Linux CtrlAlt3+ terminal.

As others have pointed out, on Mac, open does do what you would assume it does. I am not a Mac user, so I can't extend this paragraph.

However, Windows has it's own version of those commands: start example.txt opens Notepad, start example.docx runs Word, you get the idea. However, Windows is Windows, so start can be as smart as the update writers: start "my file.txt" opens a command prompt window titled my file.txt.

Solution 5 - Linux

For opening a file to write in Ubuntu on Windows bash, you can type -:

> nano filename.txt

The above command will allow you to write/edit in the file after which, you can use ctrl+x and then press 'y' to save. Check/view the file content using -:

> cat filename.txt

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPetsView Question on Stackoverflow
Solution 1 - LinuxSharath BJView Answer on Stackoverflow
Solution 2 - LinuxLanceView Answer on Stackoverflow
Solution 3 - LinuxhcheungView Answer on Stackoverflow
Solution 4 - LinuxNathan KulzerView Answer on Stackoverflow
Solution 5 - LinuxKalpana UpadhyayView Answer on Stackoverflow