@@ -530,9 +530,11 @@ int main(int argc, char ** argv) {
530
530
exit (1 );
531
531
}
532
532
533
+ const bool control_token_allowed_on_standard_stream = !params.conversation && sparams.grammar .empty ();
534
+
533
535
#ifndef _MSC_VER
534
536
const bool control_token_descriptor_is_attached = fcntl (CONTROL_TOKEN_FILENO, F_GETFL) != -1 ;
535
- if (!control_token_descriptor_is_attached && !params. conversation && sparams. grammar . empty () ) {
537
+ if (control_token_allowed_on_standard_stream && !control_token_descriptor_is_attached ) {
536
538
// Control Token File Descriptor has nothing attached to it so make control token file descriptor be an alias of stdout
537
539
// This is not done however if we are in conversation mode or grammar mode as that is typically discarded
538
540
dup2 (STDOUT_FILENO, CONTROL_TOKEN_FILENO);
@@ -759,19 +761,19 @@ int main(int argc, char ** argv) {
759
761
fflush (stdout);
760
762
fprintf (stdout, " %s" , token_str.c_str ());
761
763
} else if (!params.ctrl_token_no_out ) {
762
- if (!params.conversation && sparams.grammar .empty ())
763
- {
764
- // Stream Control Token To Special Token Output. Useful for debugging control token behaviour
765
- fflush (stdout);
766
- fprintf (stdout, " %s" , token_str.c_str ());
767
- }
768
764
#ifndef _MSC_VER
769
- else {
765
+ if (control_token_descriptor_is_attached) {
770
766
// Stream Control Token To Special Token Output. Useful for debugging control token behaviour
771
767
ssize_t result = write (CONTROL_TOKEN_FILENO, token_str.c_str (), token_str.length ());
772
768
(void ) result;
773
- }
769
+ } else
774
770
#endif
771
+ if (control_token_allowed_on_standard_stream)
772
+ {
773
+ // Stream Control Token To Standard Output Stream
774
+ fflush (stdout);
775
+ fprintf (stdout, " %s" , token_str.c_str ());
776
+ }
775
777
}
776
778
// Record Displayed Tokens To Log
777
779
// Note: Generated tokens are created one by one hence this check
0 commit comments