Created
February 1, 2023 07:09
-
-
Save appgurueu/5574544fbfaed0e732baad521c0f4fba to your computer and use it in GitHub Desktop.
Script to launch a program after reopening stdin in binary mode on Windows (untested)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <unistd.h> | |
#include <assert.h> | |
int main(int argc, char** argv) { | |
if (argc < 1) { | |
printf("Arguments: <program> {args}\n"); | |
return 1; | |
} | |
// See https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/setmode?redirectedfrom=MSDN&view=msvc-170 | |
if (_setmode(_fileno(stdin), _O_BINARY) == -1) | |
perror("_setmode failed"); | |
execvp("lua", ++argv); | |
// execvp only returns if there is an error | |
perror("execvp failed"); | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment