Seeker14491 / opener

Open a file or link in the system default program.
Apache License 2.0
49 stars 10 forks source link

Browser not opening on Linux #4

Closed Seeker14491 closed 1 year ago

Seeker14491 commented 4 years ago

Under certain conditions, nothing happens when trying to open a website using opener::open, while manually using xdg-open works fine. I suspect this is due to spawning the command with a null stdout. This is the current code where the command is configured:

let mut cmd = Command::new(cmd)
        .args(extra_args)
        .arg(path)
        .stdin(stdin_type)
        .stdout(Stdio::null())
        .stderr(Stdio::piped())
        .spawn()?;

The reason null stdout was used was to prevent polluting the user's terminal with output from xdg-open.

Seeker14491 commented 4 years ago

@japrogramer continuing our discussion from https://github.com/rust-lang/rustup.rs/issues/1125, if you don't mind, I'd like you to check if my updated branch works for you by running the following commands.

First, confirm the bug triggers on the master branch:

git clone https://github.com/Seeker14491/opener.git
cd opener/opener-bin/
echo 'Hello' > index.html
cargo run -- index.html

If you get the message Opened path successfully., but nothing happens, you've triggered the bug.

Then, check if the inherit-stdio branch works correctly and opens your browser:

git checkout -f inherit-stdio
echo 'Hello' > index.html
cargo run -- index.html
japrogramer commented 4 years ago

The first set of commands work.

▶ cargo run -- index.html                                                                     69%
   Compiling unicode-width v0.1.6
   Compiling rustc-demangle v0.1.16
   Compiling ansi_term v0.11.0
   Compiling cfg-if v0.1.10
   Compiling strsim v0.8.0
   Compiling vec_map v0.8.1
   Compiling opener v0.4.1 (/home/archangel/Code/Rust/opener/opener)
   Compiling libc v0.2.65
   Compiling bitflags v1.2.1
   Compiling textwrap v0.11.0
   Compiling atty v0.2.13
   Compiling backtrace-sys v0.1.32
   Compiling backtrace v0.3.40
   Compiling clap v2.33.0
   Compiling failure v0.1.6
   Compiling structopt v0.3.3
   Compiling opener-bin v0.1.0 (/home/archangel/Code/Rust/opener/opener-bin)
    Finished dev [unoptimized + debuginfo] target(s) in 13.75s
     Running `/home/archangel/Code/Rust/opener/target/debug/opener-bin index.html`
Opened path successfully.

and the second in the other branch also works

▶ cargo run -- index.html                                                                   67%
   Compiling proc-macro2 v1.0.6
   Compiling unicode-xid v0.2.0
   Compiling syn v1.0.5
   Compiling libc v0.2.65
   Compiling cc v1.0.46
   Compiling bitflags v1.2.1
   Compiling unicode-width v0.1.6
   Compiling unicode-segmentation v1.3.0
   Compiling failure_derive v0.1.6
   Compiling vec_map v0.8.1
   Compiling strsim v0.8.0
   Compiling rustc-demangle v0.1.16
   Compiling ansi_term v0.11.0
   Compiling cfg-if v0.1.10
   Compiling opener v0.4.1 (/home/archangel/Code/Rust/opener/opener)
   Compiling textwrap v0.11.0
   Compiling heck v0.3.1
   Compiling backtrace-sys v0.1.32
   Compiling atty v0.2.13
   Compiling clap v2.33.0
   Compiling quote v1.0.2
   Compiling backtrace v0.3.40
   Compiling proc-macro-error v0.2.6
   Compiling synstructure v0.12.1
   Compiling structopt-derive v0.3.3
   Compiling failure v0.1.6
   Compiling structopt v0.3.3
   Compiling opener-bin v0.1.0 (/home/archangel/Code/Rust/opener/opener-bin)
    Finished dev [unoptimized + debuginfo] target(s) in 28.58s
     Running `/home/archangel/Code/Rust/opener/target/debug/opener-bin index.html`
Opened path successfully.

but still this doesnt

rustup doc --std 
▶ rustup component add rust-docs                                                          
info: component 'rust-docs' for target 'x86_64-unknown-linux-gnu' is up to date
▶ uname -r; pacman -Q linux                                                                
5.3.6-arch1-1-ARCH
linux 5.3.7.arch1-1
▶ rustup --version                                                                         
rustup 1.20.2 (13979c968 2019-10-16)
Seeker14491 commented 4 years ago

@japrogramer to be clear, the first set of commands opens your browser? If so, can you check if this command opens the docs in your browser (make sure to run on the master branch):

cargo run -- $(rustup doc --std --path)

If all these commands work fine, then maybe the problem really is in rustup.

japrogramer commented 4 years ago

Yes they work, But the rustup doc command doesn't

Here the index page i created works and the one pointing to std doesnt

Rust/opener/opener-bin  master ✗                                                                18d ◒  ⍉
▶ cargo run -- index.html                                                                      ∞
    Finished dev [unoptimized + debuginfo] target(s) in 0.04s
     Running `/home/archangel/Code/Rust/opener/target/debug/opener-bin index.html`
Opened path successfully.

Rust/opener/opener-bin  master ✗                                                                 18d ◒
▶ cargo run -- $(rustup doc --std --path)                                                       ∞
    Finished dev [unoptimized + debuginfo] target(s) in 0.04s
     Running `/home/archangel/Code/Rust/opener/target/debug/opener-bin /home/archangel/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/share/doc/rust/html/std/index.html`
Opened path successfully.

Rust/opener/opener-bin  master ✗                                                                 18d ◒
▶ rustup doc --std --path                                                                       ∞
/home/archangel/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/share/doc/rust/html/std/index.html

both files have the same permissions, and the std/index.html does have content

japrogramer commented 4 years ago

Works strace -f -s100 cargo run -- index.html &> ~/errors.txt

Doesn't work strace -f -s100 cargo run -- $(rustup doc --std --path) &> ~/errors2.txt

works

firefox $(rustup doc --std --path)
julienp17 commented 4 years ago

Same issue here, the following works

firefox $(rustup doc --path)

but not

firefox $(rustup doc)

which opens KTorrent for me. I followed some instructions from rustup doc appears to do nothing #1125, by removing

[Default Applications] text/html=ktorrent.desktop

from ~/.config/mimeapps.list and replacing it with text/html=firefox.desktop but it didn't fix the issue.

My config: 5.5.3-arch1-1 linux 5.5.3.arch1-1 rustup 1.21.1 (2020-01-25) rust-docs up to date

Seeker14491 commented 3 years ago

I was never able to reproduce this issue locally, unfortunately. Anyways, I released v0.5 of this crate about two weeks ago, and it changes the strategy on Linux such that the system xdg-open is tried first if available. I'd like to know if this is still a problem with the new version. Note that a version of Rustup with the updated opener version still hasn't shipped, so to test this, a procedure like I described in https://github.com/Seeker14491/opener/issues/4#issuecomment-544786010 can be used.

gdnathan commented 3 years ago

as asked in here, i'll respond to this.

I use WSL, and xdg-open-wsl (which i can call with xdg-open on my system

Seeker14491 commented 3 years ago

@Erudyx Ah, WSL should work fine with the release of v0.5. Still, if you want to confirm it's fixed now you can run what I posted above:

git clone https://github.com/Seeker14491/opener.git
cd opener/opener-bin/
echo 'Hello' > index.html
cargo run -- index.html
gdnathan commented 3 years ago

Its working fine, but i dont i dont know why rustup doc --book does nothing... no error printed, return 0...

Seeker14491 commented 3 years ago

That's because the currently released version of rustup is using v0.4.1 of this crate. There hasn't been a rustup release since I made the PR updating to v0.5.

gdnathan commented 3 years ago

ooooh i get it, so this gonna be fixed when the pr is accepted, thanks for your time!

Seeker14491 commented 1 year ago

I'm closing this issue. Feel free to make a new issue if this is still a problem with the current version of the library.