For the benefit of Ajm ( he's threating to use languages other than purebasic if the console commands don't improve - gasp!) here's a quick example I created by expanding wichtel's scrolling console tip into procedures.
Allows console program output to be sent to a file ( eg. myprogram > myfile.txt ) or to a pipe (e.g. myprogram | more ) or to the screen of course.
Code: Select all
; allows console output to scroll and be redirected to file and pipe
; expanded version of wichtel's scrolling console example
; does not support ansi ( ie. color) or unicode
; as writefile is used in place of writeconsole - see api doc
Global stdout.l ; stdout handle
Procedure.l MyOpenConsole()
stdout = GetStdHandle_(#STD_OUTPUT_HANDLE) ; check if we already have a console ie. command prompt
If stdout = #INVALID_HANDLE_VALUE ; no we don't have existing console
If allocconsole_() ;attempt to open a new one
stdout=GetStdHandle_(#STD_OUTPUT_HANDLE)
Else
ProcedureReturn #FALSE
EndIf
EndIf
ProcedureReturn #TRUE
EndProcedure
Procedure.l MyPrintN(Stringparm.s)
written.l
msg$ = Stringparm + Chr(13) + Chr(10)
size.l=Len(msg$)
res = writefile_(stdout,@msg$,size, @written, #NULL)
Delay(30)
ProcedureReturn res
EndProcedure
Procedure.l MyCloseConsole()
Delay(1000)
res = freeconsole_()
ProcedureReturn res
EndProcedure
; Main program
If MyOpenConsole()
For i=1 To 100
MyPrintN("hello world "+Str(i))
Next i
MyCloseConsole()
EndIf
viewtopic.php?p=30314
Regards
Insomniac