Skip to content

Instantly share code, notes, and snippets.

@appgurueu
Created February 1, 2023 07:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save appgurueu/5574544fbfaed0e732baad521c0f4fba to your computer and use it in GitHub Desktop.
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)
#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