Skip to content

Commit

Permalink
VT flavor now allows for redirection of stdout, with some caveats : i…
Browse files Browse the repository at this point in the history
…t manages this by sending output to stderr, so if you redirect stderr in Windows, or both stdout and stderr in Linux or MacOS, it'll still fail. Motivated by issue #256,  which is about input (so this doesn't actually address that issue.)
  • Loading branch information
Bill-Gray committed Dec 24, 2022
1 parent 570aa79 commit 65939aa
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion vt/pdcdisp.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static void put_to_stdout( const char *buff, size_t bytes_out)
{
static char *tbuff = NULL;
static size_t bytes_cached;
const int stdout_fd = 1;
static int stdout_fd = -1;

if( !buff && !tbuff)
return;
Expand All @@ -42,6 +42,24 @@ static void put_to_stdout( const char *buff, size_t bytes_out)
return;
}

if( stdout_fd == -1)
{
#ifdef _WIN32
// if( FILE_TYPE_CHAR == GetFileType( GetStdHandle( STD_OUTPUT_HANDLE)))
stdout_fd = 2;
#else
if( isatty( STDOUT_FILENO))
stdout_fd = STDOUT_FILENO; /* stdout hasn't been redirected; use it */
else if( isatty( STDERR_FILENO))
stdout_fd = STDERR_FILENO; /* stdout is redirected to a file; use stderr */
else
{
fprintf(stderr, "No output device found\n");
exit( -1);
}
#endif
}

if( buff && !tbuff)
tbuff = (char *)malloc( TBUFF_SIZE);
while( bytes_out || (!buff && bytes_cached))
Expand Down

0 comments on commit 65939aa

Please sign in to comment.