Capturing program output

Just starting out? Need help? Post your questions and find answers here.
StanDan
User
User
Posts: 57
Joined: Sun Feb 26, 2006 3:43 am
Location: Missouri, United States

Capturing program output

Post by StanDan »

I'm doing something that you would think would be blindingly simple, yet I'm tripping all over myself finding an answer. How can I pop up a window asking a user for a value and then capture that from STDOUT? This works on Linux and Mac but not Windows.

Code: Select all

OpenConsole()
If OpenWindow(0, 100,100,200, 200, "Best power ranger?")
  StringGadget(1, 10, 10, 180, 140, "")
  ButtonGadget(2, 10, 150, 180, 30, "Done")
EndIf

Repeat
  Event = WaitWindowEvent()
  If Event = #PB_Event_Gadget
    If EventGadget() = 2
      PrintN( GetGadgetText(1) )
      End
    EndIf
  EndIf
Until Event = #PB_Event_CloseWindow
What I want to be able to do is make a simple little pop-up which asks for something from a scripting language. Like so:

Code: Select all

$variable = `demo.exe`
It seems like it loses it's connection to the console when I run the program and I don't get the output. Also, I don't really need the console window so I'm hiding it with ShowWindow_() and GetConsoleWindow_(). I'm feeling pretty sad about the prospects of this working. Is it possible?

Many thanks in advance.
Sirius-2337
User
User
Posts: 59
Joined: Sat May 14, 2011 10:39 am

Re: Capturing program output

Post by Sirius-2337 »

The PB Help for PrintN() says
To output raw data on the non-graphical console (for pipe communication) WriteConsoleData() can be used.
StanDan
User
User
Posts: 57
Joined: Sun Feb 26, 2006 3:43 am
Location: Missouri, United States

Re: Capturing program output

Post by StanDan »

Thank you. I'm not sure how I missed that.
StanDan
User
User
Posts: 57
Joined: Sun Feb 26, 2006 3:43 am
Location: Missouri, United States

Re: Capturing program output

Post by StanDan »

Yikes, still doesn't work.

Code: Select all

str.s = "Whooolly Booly"

WriteConsoleData(@str, Len(str))
With the above code compiled with either Windows or Console set, I get the following.

Code: Select all

C:\Users\jonathan\dev\Citation>perl -le "print `build\test.exe`"


C:\Users\jonathan\dev\Citation>ruby -e "puts `build\\test.exe`"


C:\Users\jonathan\dev\Citation>build\test.exe

Is the bug in PureBasic... or my poor brain?
StanDan
User
User
Posts: 57
Joined: Sun Feb 26, 2006 3:43 am
Location: Missouri, United States

Re: Capturing program output

Post by StanDan »

Finally got it, it was missing OpenConsole(), which is required for it to work but there's no warning about it being needed.

Code: Select all

str.s = "Whooolly Booly"
OpenConsole()
WriteConsoleData(@str, Len(str))
This works. Thank you guys!
Post Reply