Skip to content
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

Empty arguments to processes aren't handled correctly on windows #16272

Closed
alexcrichton opened this issue Aug 5, 2014 · 4 comments · Fixed by #16284
Closed

Empty arguments to processes aren't handled correctly on windows #16272

alexcrichton opened this issue Aug 5, 2014 · 4 comments · Fixed by #16284
Labels
O-windows Operating system: Windows

Comments

@alexcrichton
Copy link
Member

For example, this program prints "1\n3" on unix, and "1\n2" on windows:

use std::io::{process, Command};
use std::os;

fn main() {
    let len = os::args().len();
    println!("{}", len);

    if len == 1 {
        Command::new(os::self_exe_name().unwrap())
                .arg("foo").arg("")
                .stdout(process::InheritFd(1))
                .spawn().unwrap();
    }
}
@alexcrichton
Copy link
Member Author

The appears to be different on windows for both libgreen and libnative.

@aturon
Copy link
Member

aturon commented Aug 5, 2014

I believe this happens because the arguments end up being quoted for Windows. Simplest fix would be to drop empty arguments. Thoughts?

@aturon
Copy link
Member

aturon commented Aug 5, 2014

(Alternatively, we could quote empty arguments on Unix.)

@alexcrichton
Copy link
Member Author

I would expect the empty arguments to be passed through as significant argument position. I ran into this in cargo because Command::new("rustdoc").arg("--test-args").arg("") passed on unix but on windows it would try to consume the next argument for the test args.

It looks like to fix this we just need to alter this condition to see if the argument is 0-length, and if so we quote it. Libuv already does something similar.

I'm investigating a fix for libgreen, it looks like it should be working...

alexcrichton added a commit to alexcrichton/rust that referenced this issue Aug 6, 2014
There was a bug in both libnative and libuv which prevented child processes from
being spawned correctly on windows when one of the arguments was an empty
string. The libuv bug has since been fixed upstream, and the libnative bug was
fixed as part of this commit.

When updating libuv, this also includes a fix for rust-lang#15149.

Closes rust-lang#15149
Closes rust-lang#16272
bors added a commit that referenced this issue Aug 12, 2014
There was a bug in both libnative and libuv which prevented child processes from
being spawned correctly on windows when one of the arguments was an empty
string. The libuv bug has since been fixed upstream, and the libnative bug was
fixed as part of this commit.

When updating libuv, this also includes a fix for #15149.

Closes #15149
Closes #16272
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-windows Operating system: Windows
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants