How do I write to a terminal using under linux? (if possible multiplatform then better too)
For example in Ubuntu you can open two terminal, type 'tty' to get the handle. and you can pipe between them. for example you can type in one but the output get out on the other one.
So the question is...
1. how do I open a new terminal window in PureBasic and already have the handle?
2. or if I already have a terminal window open, provide this to PureBasic?
3. how to I write to terminal? including newline?
for example this:
-a person open a terminal window
-run my app
-provide the tty handle to my app
-my app ask for name
-print out "Hello name" in the terminal window.
-and provide a new line / enter
-so that I can also send 'echo 'name' to the terminal and press enter.
even a simple example can be helpful. you know, something as simple as:
-ask for terminal tty handle
-print hello world in the terminal
Thanks.
writing to linux terminal
Re: writing to linux terminal
One possibility is to have your user (from the opened terminal) execute a script to place the results from the tty command into a disk file that your PB program can sense.Fable Fox wrote:How do I write to a terminal using under linux? (if possible multiplatform then better too)
For example in Ubuntu you can open two terminal, type 'tty' to get the handle. and you can pipe between them. for example you can type in one but the output get out on the other one.
So the question is...
1. how do I open a new terminal window in PureBasic and already have the handle?
2. or if I already have a terminal window open, provide this to PureBasic?
I found this code on my hard drive from back when I was investigating console use.3. how to I write to terminal? including newline?
for example this:
-a person open a terminal window
-run my app
-provide the tty handle to my app
-my app ask for name
-print out "Hello name" in the terminal window.
-and provide a new line / enter
-so that I can also send 'echo 'name' to the terminal and press enter.
even a simple example can be helpful. you know, something as simple as:
-ask for terminal tty handle
-print hello world in the terminal
Thanks.
Code: Select all
BLACK= RGB(0,0,0) : GRAY= RGB(128,128,128) : WHITE= RGB(255,255,255) : GREEN= RGB(0,255,0)
NAME$= "COCONUT MILK" : #FLAGS= #PB_Window_ScreenCentered|#PB_Window_MinimizeGadget
If OpenWindow(0,0,0,800,600,"Console Test",#FLAGS)=0 : End : EndIf
If InitSprite()=0 : End : EndIf
If OpenWindowedScreen(WindowID(0),0,0,800,600,#True,0,0)=0 : End : EndIf
If InitKeyboard()=0 : End : EndIf
While WindowEvent() : Wend
ClearScreen(GRAY) : StartDrawing(ScreenOutput()) : Box(5,5,790,590,BLACK)
DrawText(10,10,"PRESS ENTER TO ACTIVATE INPUT THROUGH CONSOLE OR PRESS Esc TO EXIT.",WHITE)
StopDrawing() : FlipBuffers() : TY= 50
Repeat
While WindowEvent() : Wend
ExamineKeyboard()
; EXIT PROGRAM WHEN USER PRESSES ESCAPE KEY
If KeyboardPushed(#PB_Key_Escape) : End : EndIf
If WaitWindowEvent(20)= #PB_Event_CloseWindow : End : EndIf
If KeyboardPushed(#PB_Key_Return)
Repeat : While WindowEvent() : Wend : ExamineKeyboard() : Until Not KeyboardPushed(#PB_Key_All)
NEWNAME= 0
StartDrawing(ScreenOutput())
DrawText(10,TY,"ACTIVATING CONSOLE",GREEN) : TY+ 20
StopDrawing() : FlipBuffers()
If OpenConsole()
ConsoleTitle ("A Wonderful Application")
PrintN("Type in your name and press Enter, or just press Enter to use "+NAME$+".")
USER$= Input()
If Len(USER$)>0
If Len(USER$)<25 : NAME$= USER$
Else
NAME$= Mid(USER$,1,24)
EndIf
NEWNAME= 1
EndIf
CloseConsole()
Repeat : While WindowEvent() : Wend : ExamineKeyboard() : Until Not KeyboardPushed(#PB_Key_All)
If NEWNAME
StartDrawing(ScreenOutput())
DrawText(10,TY,"YOUR NEW NAME IS "+NAME$,GREEN) : TY+20
StopDrawing() : FlipBuffers()
EndIf
EndIf
EndIf
ForEver
Keep it BASIC.