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

Implements the Windows version of sys/exec #3

Open
alaviss opened this issue Feb 2, 2021 · 6 comments
Open

Implements the Windows version of sys/exec #3

alaviss opened this issue Feb 2, 2021 · 6 comments
Labels
enhancement New feature or request

Comments

@alaviss
Copy link
Owner

alaviss commented Feb 2, 2021

Target: Vista+

Problems:

  • CMD and Windows has different parameter quoting algo (and all of them sucks).
  • Not everything in PATHEXT can be run directly (need confirmation on whether CreateProcess can launch .bat directly or cmd.exe has to be used).
  • inherits is racy on Windows since the inheritable state is global, and we need to restore it afterwards. Probably a lock is the best way atm.
@alaviss alaviss changed the title Implements the Windows version of nim-sys Implements the Windows version of sys/exec Feb 2, 2021
@alaviss alaviss added the enhancement New feature or request label Feb 2, 2021
@alaviss
Copy link
Owner Author

alaviss commented Feb 2, 2021

Depends on #2 and #1, we need a path library for findExe and NullessString for process execution.

@barcharcraz
Copy link

There are no parameter quoting rules on windows. Parameters are always a single string with all parameters. The CRT splits them up again in userspace for compatibility with C programs.

@alaviss
Copy link
Owner Author

alaviss commented Apr 29, 2021

There is a quoting rule to distinguish C:\Program Files and ["C:\Program", "Files"]. You can read more about it here. The cmd.exe unquoting algo is even worse

The stupid thing with Windows is that programs can implement their own un-quoting scheme, of which msiexec and cmd are the two widely used offenders as far as I know.

@barcharcraz
Copy link

yes, the quoting rules described above are properties of the CRT, if you don't use the CRT you don't get those rules and just get one big parameter string (it's actually similar to how linux deals with parameters passed to executable interpreters). Linux actually keeps parameter arrays separated by parameter as they work their way through the kernel from one process to another.

I've been trying to think of a way to make things easier, it would be good if the CRT's version of the posixey exec functiosn actually did the escaping correctly (they just join the arguments with spaces).

@alaviss
Copy link
Owner Author

alaviss commented Apr 30, 2021

yes, the quoting rules described above are properties of the CRT, if you don't use the CRT you don't get those rules and just get one big parameter string (it's actually similar to how linux deals with parameters passed to executable interpreters). Linux actually keeps parameter arrays separated by parameter as they work their way through the kernel from one process to another.

Yes but sys/exec has to cater to the most common case. I have already planned a Windows-specific API to call with your own argument string in case you have to deal with Windows application that doesn't parse like the CRT.

I've been trying to think of a way to make things easier, it would be good if the CRT's version of the posixey exec functiosn actually did the escaping correctly (they just join the arguments with spaces).

Unfortunately for the kind of control that sys/exec has to exert on process creation, we can't use the APIs exposed by the CRT.

@barcharcraz
Copy link

yeah. Even a function in windows would be easier than the "real" fix of getting an actual new syscall to do it. (instead of the current easiest syscall which is NtCreateUserProcess. (I'm actually not sure if that's a "real" syscall)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants