-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
std::process::Command feature request: .launch() or .start() #50679
Comments
Isn't that what |
Not on Windows. If you use spawn() to run |
The docs on
So it should already work. Have you tried usiing |
Here's an example: use std::process::Command;
use std::thread;
use std::time;
fn main() {
println!("Start");
let _child = Command::new("cmd.exe")
.arg("/C").arg("start").arg("").arg("http://www.rust-lang.org")
.spawn().expect("failed to launch browser");
thread::sleep(time::Duration::new(10, 0)); // Windows needs time!
println!("End");
} If no web browser is running: If you do It is not possible to just use use std::process::Command;
use std::thread;
use std::time;
fn main() {
println!("Start");
let _child = Command::new("start")
.arg("").arg("http://www.rust-lang.org")
.spawn().expect("failed to launch browser");
thread::sleep(time::Duration::new(10, 0)); // Windows needs time!
println!("End");
} Doesn't work:
|
What happens if you start the command without piped I/O? The Addendum: |
Related issue: rust-lang/cargo#4575 |
retep998: you are quite right! When I run the .exe directly it works as expected: the browser is launched at the right page or a new tab is opened if it is already running, and it keeps running even when the rust .exe finishes. Sorry for my mistake! |
I would give you 10+ likes , if i could. Your „mistake“ saved my day! 😁 |
let mut cmd = Command::new("C:/Windows/System32/rundll32.exe");
cmd.args(
["url.dll,FileProtocolHandler", url]
);
cmd.spawn()?; Not the best solution, but better than nothing... |
Only |
hm, as in the case of a windows disk installer that use X: in the case of just calling the command by name, there are search priorities and through this the binaries can be spoofed + if you don't specify an extension, the com program will be called first, which can also be spoofed. |
The current API for std::process::Command() is ideal for starting an external process and waiting for it to finish. However, there are use cases where you want to start an external process, get immediate feedback on whether it started or not, and then continue (or finish), without waiting for the external process to finish at all.
For example, you might have
--help
for showing command line options, and--manual
to show a full manual which you want to show by starting a web browser at a given URL but don't want the browser window to close when the rust app finishes straight after opening the browser. Similarly, you might have an app that produces results and has a--show
option that tells the app to launch an app to show the results (spreadsheet, photoeditor, whatever); and again, you want the results window to hang around even though the command line app has finished.This is probably easy on Unix; but I can't find a way to do it on Windows.
The text was updated successfully, but these errors were encountered: