-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Feature request: add method to unix::process::CommandExt to set argv[0] #66510
Comments
This comment has been minimized.
This comment has been minimized.
This allows argv[0] to be overridden on the executable's command-line. This also makes the program executed independent of argv[0]. Does Fuchsia have the same semantics? Addresses: rust-lang#66510
Add unix::process::CommandExt::arg0 This allows argv[0] to be overridden on the executable's command-line. This also makes the program executed independent of argv[0]. Does Fuchsia have the same semantics? I'm assuming so. Addresses: rust-lang#66510
This allows argv[0] to be overridden on the executable's command-line. This also makes the program executed independent of argv[0]. Does Fuchsia have the same semantics? Addresses: rust-lang#66510
Add unix::process::CommandExt::arg0 This allows argv[0] to be overridden on the executable's command-line. This also makes the program executed independent of argv[0]. Does Fuchsia have the same semantics? I'm assuming so. Addresses: rust-lang#66510
Add unix::process::CommandExt::arg0 This allows argv[0] to be overridden on the executable's command-line. This also makes the program executed independent of argv[0]. Does Fuchsia have the same semantics? I'm assuming so. Addresses: rust-lang#66510
This can be closed in light of #66512 , correct? |
yup |
2 remarks:
|
@glandium I don't know much about Windows, and my assumption was that it wouldn't apply, at least not directly. Looking at rust/src/libstd/sys/windows/process.rs Line 165 in 1ce08f9
program is passed to the system separately from the command-line at all, so passing a different value for the first argument will just override the executable being executed. In the Unix model, the path to the executable and the first argument passed to it are independent (though conventionally related).
|
libstd passes null as first argument to rust/src/libstd/sys/windows/process.rs Line 205 in 1ce08f9
but it could be set to the actual executable, in which case the first "argument" in the command line would become argv0 in the launched process. |
I believe it should, re-opening. |
@glandium I had a quick look at implementing it for Windows, but it seems pretty complex.
I had been hoping to spend a little bit of time to bring Windows to feature parity with Unix here, but I'm way out of my depth. I think this needs to be implemented and stabilized for Windows separately. |
This stabilizes process_set_argv0 targeting 1.45.0. It has been useful in practice and seems useful as-is. The equivalent feature could be implemented for Windows, but as far as I know nobody has. That can be done separately. Tracking issue: rust-lang#66510
Stabilize process_set_argv0 feature for Unix This stabilizes process_set_argv0 targeting 1.45.0. It has been useful in practice and seems useful as-is. The equivalent feature could be implemented for Windows, but as far as I know nobody has. That can be done separately. Tracking issue: rust-lang#66510
Since it looks like Windows support requires some more exploration and the feature as described has been stabilized, I'll go ahead and close this tracking issue. If anybody wants to drive Windows support that would be most welcome! |
In Unix, the first process argument is the executable name by convention. However, there are various occasions where you might want to set argv[0] to something other than the full executable path:
I suggest adding a
set_argv_0<S: AsRef<OsStr>(&mut self, arg: S) -> process::Command
tostd::os::unix::process::CommandExt
to allow argv[0] to be overridden.The default behaviour would remain unchanged.
It would require a little more implementation change - currently it always executes
self.get_argv()[0]
, but this should be changed toself.program.as_ptr()
.The text was updated successfully, but these errors were encountered: