unusual (print buffering on FreeBSD

Machine-specific discussion
Unix, Linux, OS X, OS/2, Windows, ..?
Locked
CaveGuy
Posts: 112
Joined: Sun Oct 13, 2002 3:00 pm
Location: Columbus Ohio
Contact:

unusual (print buffering on FreeBSD

Post by CaveGuy »

The following test program runs just fine on both windows and ubuntu Linux but has print buffering problems and fails on FreeBSD 11.1.

Code: Select all

;; (load "test.lsp")
#
; pressing key1 returns true, key2 returns nil, all other keys ignored
(define (torf key1 key2) 
   (setq keypress2 "")
   (while (and (!= keypress2 key1) (!= keypress2 key2)) 
          (setq keypress2 (upper-case (char (read-key)))))
   (= keypress2 key1) )
#
; dummy compile/link code for testing
(define (linkme)
    (setq compile true
          exename "test")
    (println "\ncompile/link code runs here")
    nil) ; return no errors
#
; mainline program edited for testing
(define (doit)
     (println "do main program here")
     (sleep 5000) ; pause for effect
     (println "then exit")
     (fake-exit) )
#
; entry point for this test
(define (run)
   (if (not compiled)
      (begin
         (print "\n \"C\"ompile or \"R\"un ? " )
         (if (torf "C" "R")
              (begin
                   (if (not (linkme)) 
                         (println (string "\n Compile of " exename " was successful. "))
                         (println (string "\n Compile of " exename " failed! ")))
                   (print " \"E\"xit or \"T\"est ? ")
                   (if (torf "T" "E") 
                       (doit)
                       (print "\nfinished")))
             (doit)))
      (doit))
  true
  )
  true
  ;eof
here is a sample good run on ubuntu.

Code: Select all

newLISP v.10.7.1 64-bit on Linux IPv4/6 UTF-8 libffi, options: newlisp -h

> (load "test.lsp")
true
> (run)

 "C"ompile or "R"un ?  [i]; entered "c" for compile[/i]
compile/link code runs here

 Compile of test was successful.
 "E"xit or "T"est ?
finished 
and failing example on BSD

Code: Select all

root@bsd1:/home/bob # newlisp
newLISP v.10.6.2 64-bit on BSD IPv4/6 UTF-8 libffi, options: newlisp -h

> (load "test.lsp")
true
> (run)
;[i] the program stops at this point waiting on input with no prompt.
; enter an "c" to exit as if the prompt was there and it 
; flushes the print buffer and continues.[/i]
 "C"ompile or "R"un ?
compile/link code runs here
[i]; and stops again waiting on input with no prompt.
; enter an "e" to exit as if the prompt was there again
; flushes the print buffer and we continue to the exit.[/i]
Compile of test was successful.
"E"xit or "T"est ?
finished 
>
This leaves me clueless, I will test later on cent-os as soon as I can get another VM running.
Bob the Caveguy aka Lord High Fixer.

rickyboy
Posts: 607
Joined: Fri Apr 08, 2005 7:13 pm
Location: Front Royal, Virginia

Re: unusual (print buffering on FreeBSD

Post by rickyboy »

Try using `write` with the length argument, as it seems to be non-buffering in this case.

Code: Select all

$ diff -u test.lsp test-new.lsp
--- test.lsp    Mon Aug  7 08:51:48 2017
+++ test-new.lsp        Mon Aug  7 08:53:45 2017
@@ -20,18 +20,20 @@
      (sleep 5000) ; pause for effect
      (println "then exit")
      (fake-exit) )
+
+(define (prompt-user STR) (write 1 STR (length STR)))
 #
 ; entry point for this test
 (define (run)
    (if (not compiled)
       (begin
-         (print "\n \"C\"ompile or \"R\"un ? " )
+         (prompt-user "\n \"C\"ompile or \"R\"un ? " )
          (if (torf "C" "R")
               (begin
                    (if (not (linkme))
                          (println (string "\n Compile of " exename " was successful. "))
                          (println (string "\n Compile of " exename " failed! ")))
-                   (print " \"E\"xit or \"T\"est ? ")
+                   (prompt-user " \"E\"xit or \"T\"est ? ")
                    (if (torf "T" "E")
                        (doit)
                        (print "\nfinished")))
(λx. x x) (λx. x x)

CaveGuy
Posts: 112
Joined: Sun Oct 13, 2002 3:00 pm
Location: Columbus Ohio
Contact:

Re: unusual (print buffering on FreeBSD

Post by CaveGuy »

Thanks that works just fine :)

I will use that trick in some other common code ie. (myprintln ... and all should be fixed.

Thanks again ...
Bob the Caveguy aka Lord High Fixer.

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Re: unusual (print buffering on FreeBSD

Post by Lutz »

In newLISP version 10.7.3 ‘print’ to standard out will also flush on macOS and other BSDs:

http://newlisp.nfshost.com/downloads/de ... nprogress/

CaveGuy
Posts: 112
Joined: Sun Oct 13, 2002 3:00 pm
Location: Columbus Ohio
Contact:

Re: unusual (print buffering on ubuntu this time ..

Post by CaveGuy »

This one reared it's ugly head again this time testing 10.7.3 on ubuntu 17.10

newLISP v.10.7.3 64-bit on Linux IPv4/6 UTF-8 libffi, options: newlisp -h

> (setq x 0) (while (!= (char "x") (read-key true)) (sleep 1000)(println (inc x))) nil
0
1
2
x3
3
nil

> (setq x 0) (while (!= (char "x") (read-key true)) (sleep 1000)(print (inc x))) nil
0
x1234566
nil
Bob the Caveguy aka Lord High Fixer.

Locked