Skip to content

Commit

Permalink
Add CLI option to disable line buffering
Browse files Browse the repository at this point in the history
  • Loading branch information
jhunkeler committed Mar 7, 2024
1 parent fec3ee1 commit d9960fc
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ static struct option long_options[] = {
{"config", optional_argument, 0, 'c'},
{"python", optional_argument, 0, 'p'},
{"verbose", no_argument, 0, 'v'},
{"unbuffered", no_argument, 0, 'U'},
{"update-base", optional_argument, 0, OPT_ALWAYS_UPDATE_BASE},
{0, 0, 0, 0},
};
Expand All @@ -51,6 +52,7 @@ const char *long_options_help[] = {
"Read configuration file",
"Override version of Python in configuration",
"Increase output verbosity",
"Disable line buffering",
"Update conda installation prior to OMC environment creation",
NULL,
};
Expand Down Expand Up @@ -145,7 +147,7 @@ int main(int argc, char *argv[], char *arge[]) {
int c;
while (1) {
int option_index;
c = getopt_long(argc, argv, "hVCc:p:v", long_options, &option_index);
c = getopt_long(argc, argv, "hVCc:p:vU", long_options, &option_index);
if (c == -1) {
break;
}
Expand All @@ -168,6 +170,13 @@ int main(int argc, char *argv[], char *arge[]) {
case OPT_ALWAYS_UPDATE_BASE:
arg_always_update_base_environment = 1;
break;
case 'U':
setenv("PYTHONUNBUFFERED", "1", 1);
fflush(stdout);
fflush(stderr);
setvbuf(stdout, NULL, _IONBF, 0);
setvbuf(stderr, NULL, _IONBF, 0);
break;
case 'v':
globals.verbose = 1;
break;
Expand Down

0 comments on commit d9960fc

Please sign in to comment.