-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
In Windows, opening a file without default program does nothing (in VSCode) #73
Comments
I tried this on Windows 11 and it worked as expected.
Can you provide more information on how to reproduce this? The Windows version may affect the outcome as well, the Thank you |
Ok, now I'm really confused. It works. But when nested deep in my program it doesn't. I have checked that the path argument is exactly the same. It's a big async program with tokio and an axum web server. It stops working correctly depending on where I call I'm testing:
|
That's interesting and curious indeed! Spawn is spawn, one would think. |
I found a new quirk. I was running the program inside the built-in VSCode terminal. Running it directly in the windows terminal works as expected. The |
That's not at all the first time I am hearing that from within VSCode, opening won't work. It's even more curious that opening with a custom program works, but maybe that means there is something special about |
I have the same problem when trying to open a local .html file. Calling My fix (reusing code from Command::new("cmd")
.arg("/c")
.arg("explorer")
.raw_arg(wrap_in_quotes(filename))
.creation_flags(CREATE_NO_WINDOW)
.status()
.unwrap(); |
Thanks for sharing, it's great to have a workaround! Now I wonder if on Windows, one could just add this invocation as another option, treating the explorer invocation as additional launcher? Is this something @Fundevoge would like to contribute? Thanks for your consideration 🙏. |
…-code issue. (#73) It seems in VSCode launching with `cmd` alone doesn't work, but using `explorer` as mediator does the trick. Now on windows there is an additional launcher to try.
Actually I couldn't wait but would love it if someone could try out the branch with the fix. Once confirmed working, I'd make a patch release immediately :). Thanks for your help. |
…-code issue. (#73) It seems in VSCode launching with `cmd` alone doesn't work, but using `explorer` as mediator does the trick. Now on windows there is an additional launcher to try.
First of all, thanks for responding and working on it.
The message is identical except for that the command now is |
A possible fix would be to wrap the If someone has a better idea, please let me know. If someone has a better idea, please let me know. |
Thanks a lot for looking into this and for sharing your research. It's interesting as the issue with the exit code being inverted is happening only in VSCode, right? Because these problems simply don't exist under 'normal' circumstances. Is this true or am I getting something wrong here? Regarding the solution, it's possible to let |
When using the explorer command, I get this popup, even from VSCode, with integrated PowerShell or CMD Prompt.
The explorer command not having an exit code seems to be a windows bug, as this also happens inside a regular command prompt. |
That sounds like explorer is the same, but I'd hope that the order of I hope it makes sense and that it enables you to submit a first PR for comments. Thanks again for all your help, you are really pushing this topic forward (and hopefully soon, to completion) 🙏. |
I think I have found one source of the initial bug: let file_name = String::from(r"temp.html");
open::that(file_name).unwrap(); But this code does not: let file_name = String::from(r"temp.html");
let _file = File::create(file_name.clone()).unwrap();
open::that(file_name).unwrap();
|
Oh that's a wonderful revelation as it means there is nothing special with VSCode on Windows in particular, but it's all about the circumstances of the |
Tried to add some "sleep" for a second to make sure the file is written, as well as flush it, didn't help But then just dropping the file made it work, so it's not about a file being unavailable for reading, just that it needs to be not opened for writing?
this also fails for an existing file when it's opened for writing |
Interestingly enough, the https://docs.rs/opener/latest/opener/fn.open.html alternative doesn't suffer from this issue and can open the file even if it's being opened for writing. Its docs mention that it uses |
It's great you mention this as there is a |
Ah, so I've just rediscovered a know thing, then I guess I don't get the availability comment (FYI this API also shows the selector for unknown file types) |
Does this mean you tried the feature and it worked for you? If so, this issue can probably be closed with reference to this comment. |
yes it does, though only for might be worth adding a note to the doc that files opened for writing represent an issue Also, those tokio folks would still need a fix? |
Thanks for highlighting this, I wasn't aware. The API itself feels a bit messy with
Those who use |
When trying to open a file that has no association with any program, nothing happens and no error is returned. Normally in Windows a selector is displayed that allows the user to choose which application to use, but this does not happen.
The text was updated successfully, but these errors were encountered: