Page 1 of 1

Read console output

Posted: Sat May 24, 2008 3:20 am
by ricardo
See this example:

Code: Select all

If OpenConsole()
  ConsoleTitle("Lets see")
  ApplicationName.s = "cmd.exe /c ping google.com"
  If WinExec_(@ApplicationName.s, #SW_SHOWNORMAL) = 0  
    MessageRequester("ERROR", Str(GetLastError_()) , #PB_MessageRequester_Ok)
  EndIf
  Repeat  
    Delay(20)
  Until GetAsyncKeyState_(#VK_ESCAPE)
EndIf
End
Im trying to read the output but cant.

Yes, i know i can run it from runprogram. But the problem is that i found some commandline that dont let me catch the output by that way and im trying to see if i can do it by this way.

Thanks in advance for any help

Posted: Sat May 24, 2008 3:29 am
by ts-soft

Code: Select all

EnableExplicit

Define ping.l = RunProgram("ping", "google.com", "", #PB_Program_Open|#PB_Program_Read)
Define Output.s = ""
If ping
  While ProgramRunning(ping)
    Output + ReadProgramString(ping) + Chr(13)
  Wend
  CloseProgram(ping)
  Output + Chr(13) + Chr(13)
EndIf
MessageRequester("ping", Output)
greetings
Thomas

Posted: Sat May 24, 2008 3:32 am
by ricardo
ts-soft wrote:

Code: Select all

EnableExplicit

Define ping.l = RunProgram("ping", "google.com", "", #PB_Program_Open|#PB_Program_Read)
Define Output.s = ""
If ping
  While ProgramRunning(ping)
    Output + ReadProgramString(ping) + Chr(13)
  Wend
  CloseProgram(ping)
  Output + Chr(13) + Chr(13)
EndIf
MessageRequester("ping", Output)
greetings
Thomas

Thanks, but...
From the original post:
Yes, i know i can run it from runprogram. But the problem is that i found some commandline that dont let me catch the output by that way and im trying to see if i can do it by this way.
:twisted:

*However, even for curiosity, how can i read it from my own console like the example i show?

Posted: Sat May 24, 2008 3:59 am
by ts-soft
Okay, I overlooked or my English is not as good :oops:

Posted: Sat May 24, 2008 10:46 am
by Trond
Im trying to read the output
No, you're not. None of your code has anything to do with reading the output.

We can make a solution that works for the other program unless we know how it behaves. Ping works ok with ts-soft's code.

Posted: Wed May 28, 2008 3:56 am
by andyryu
you can use write and read pipe with winapi,then readfile from pipe
but i think purebasic do it same way
some exe redirect output ,you can catch it