Cannot open application

I tried running this:

match std::process::Command::new("notepad.exe").spawn()
        Ok(e)        => println!("{:?}", e),
        Err(e)      => println!("{}", e),

and I cannot open up notepad.exe.

This is the output I get:

Child { stdin: None, stdout: None, stderr: None }

Any idea what I should be doing to launch the application?

Also I would like to specify the entire path for an application that might be in the Desktop folder or something, I just want to make sure I can do this as well?

This output means that the child process was launched successfully, but didn't provide any standard input, output or error streams (and for notepad.exe this is probably expected). What do you do after the spawn? If you don't wait for the application to finish, it probably is closed by Windows when your program finishes.

Just pass this path to Command::new. Note however that you can't use the shortcuts, which are usually placed on desktop - you have to find first how to get the real path from them.


What about for just standard files I just want to open, how would I go about this?

What do you mean by "standard files"?

Like *.txt or anything that is not an application.

You could try using start command - start | Microsoft Docs.

1 Like

It sounds like you want to pass them as arguments. In the same way that I might run notepad.exe path\to\file.txt from the terminal, you would use something like this in Rust:


This will open the specified file with Notepad.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.