4 ms·
Well-behaved alias commands on Windows
- CodesInChaos 6y agoAssuming you own all the executables in the project: I would have compiled the main functionality into a DLL which exports a single function, and then invoked that function for the individual executables. This approach avoids the additional process and I'd expect the executables to be a bit smaller as well.
- twic 6y ago> It glues the strings together, calls CreateProcessW, waits for it to exit (WaitForSingleObject), retrieves the exit code (GetExitCodeProcess), and exits with the same status. (The stuff that comes for free with exec(3).) So does Windows not support a unix-style exec where the new process replaces the old one? The Windows C library appears to have exec, with the usual semantics: https://docs.microsoft.com/en-us/cpp/c-runtime-library/exec-wexec-functions?view=msvc-160 https://docs.microsoft.com/en-us/cpp/c-runtime-library/exec-... How is that implemented?
- ChrisSD 6y agoPresumably they start a new process and then exit the current one. `CreateProcess`[0] can allow the new process to inherit handles, etc. [0]: https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessw https://docs.microsoft.com/en-us/windows/win32/api/processth...
- gruez 6y ago>Presumably they start a new process and then exit the current one that's not exactly the same thing though. eg. if your parent process is waiting for you to exit, then creating a new process and then exiting will produce incorrect behavior. The same applies for anything that relies on pids.
- ChrisSD 6y agoI mean sure, it doesn't work exactly like Linux. It can't. Note there's nothing in the doc linked by twic that say these function maintain pids. > Each _exec function loads and executes a new process. All _exec functions use the same operating-system function (CreateProcess). I guess they could better emulate Linux using another layer of abstraction but I don't think they do. It is true that large parts of the C library in Windows is there only to emulate Unix like behaviour so as to make porting easier. But it's not meant to emulate Linux exactly (that's what WSL is for).
- deleted 6y ago[deleted]
- barosl 6y agoInteresting read! I also enjoyed another article linked from the article, which seeks to find the smallest .exe possible on Windows.[1] [1] http://www.phreedom.org/research/tinype/ http://www.phreedom.org/research/tinype/
- xeeeeeeeeeeenu 6y ago> If you, say, Ctrl+C to cancel compilation, you will get the infamous “Terminate batch job (Y/N)?” prompt which interferes with other programs running in the same console. Recently, a workaround for this issue has been discovered: https://github.com/microsoft/terminal/issues/217#issuecomment-737594785 https://github.com/microsoft/terminal/issues/217#issuecommen...