OPEN PIPE alternatives

Windows specific questions.
Post Reply
jimdunn
Posts: 13
Joined: Jan 28, 2016 15:07

OPEN PIPE alternatives

Post by jimdunn »

I noticed a couple examples of "capturing stdout" using the WINAPI over at viewtopic.php?t=1016

I know that "CreatePipe()" isn't "smaller or portable" but I want to be able to capture stdout without having the console "pop up" or "flash"...

Anyone have any "open pipe" alternative code they want to share?

Or, is there a way to force any "console" windows to be MINIMIZED by default?
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: OPEN PIPE alternatives

Post by dodicat »

Using fb open pipe command with minimized console.

Code: Select all


#include "windows.bi"

Function pipeout(Byval s As String="") Byref As String
    Var f=Freefile
    Dim As String tmp
    Open Pipe s For Input As #f 
    s=""
    Do Until Eof(f)
        Line Input #f,tmp
        s+=tmp+Chr(10)
    Loop
    Close #f
    Return s
End Function 

sub savefile(filename As String,p As String)
    Dim As long n=freefile
    If Open (filename For Binary Access Write As #n)=0 Then
        Put #n,,p
        Close
    Else
        Print "Unable to save " + filename:sleep:end
    End If
End sub

ShowWindow( getconsolewindow(), SW_MINIMIZE )

var s=pipeout("dir /w")
savefile("directory.txt",s)

shell "notepad "+"directory.txt"
kill "directory.txt"
SendMessage(getconsolewindow(), WM_CLOSE, 0, 0)


 
grindstone
Posts: 862
Joined: May 05, 2015 5:35
Location: Germany

Re: OPEN PIPE alternatives

Post by grindstone »

Have a look at https://users.freebasic-portal.de/grind ... /bipipe.bi, function bipOpen. Use SW_MINIMIZE as showmode value.
jimdunn
Posts: 13
Joined: Jan 28, 2016 15:07

Re: OPEN PIPE alternatives

Post by jimdunn »

Wow! Guys!! Thanks for the replies!!! : )
Post Reply