Redirect cmdline app output to a blitz app?
BlitzMax Forums/BlitzMax Programming/Redirect cmdline app output to a blitz app?
| ||
Any way to pipe output from a command line app to blitzmax app? I'm making a console/terminal app and I need to execute another non-blitzmax app and get it's output. I was looking in the stdio for any pipe info, but see nothing but input and print. Does anyone have any solutions that do not use Win32 api calls? Looking for a solution that will work on any supported blitzmax platform. (as a last resort I can of course pipe it to a text file and then read that in, but that takes more time than a direct pipe to my app) Thanks for any help or info, -Garrett |
| ||
Doesn't Skid's PUB.FreeProcess do that. An example (from memory):Rem Example of FreeProcess for Garrett EndRem Import Pub.FreeProcess Global myProcess:TProcess = TProcess.Create("stdioapp.exe") While (myProcess <> Null) And myProcess.Status() Print myProcess.pipe.readline$() Wend myProcess.TerminateAs you probably realise, the above code should print out any data from the process's IO stream until there is no more data to read. Then it terminates the process. This module is used by the MaxIDE to read data from the Blitz Compiler, so it cross-platform compatible. However, there is little documentation regarding it so I relied mostly on trial + error. |
| ||
That's right.... I did take a look at that before, but the lack of documentation shut me down. :-( |
| ||
Global myProcess:TProcess = TProcess.Create("stdioapp.exe") I get the following error: Compile Error: Missing function parameter 'flags' Any clue as to what flags(params) Create("app") is expecting? Thanks a bunch Seb, -Garrett |
| ||
but the lack of documentation shut me down Most commonly posted Bmax comment. (Even more than where is Max3d) |
| ||
Most commonly posted Bmax comment. (Even more than where is Max3d) Now... Now..... I wasn't trying to start anything here by that ya know! ;-) -Garrett |
| ||
Sorry, you can use either 0 or "HIDECONSOLE" depending on your desired effect. |
| ||
My sincerest apologies for bumping this old thread, but I have my reasons to do so :) I have been looking for a long time for this feature so I was happy to find it, however I could get it to work in simple actions. (My first try was simply see how it would respond to the Unix "ls" command and no problem there. Oh yeah MacOS M. Lion is my main system). But then I tried it out with something bigger like my LJCR application (of my JCR package) which is app that can take more time to handle stuff like this (as it compresses data) and also produce more output. Time after time this leads into crashes. Of course, as MaxIDE uses the same module it should work, as LJCR never caused MaxIDE to crash during my production of that app. Just to make sure it wasn't some crazy things wrong with my own LJCR app I tried the same by using "zip" to pack a pretty large folder piping the stdout results here and that too lead into a crash. It's my guess it's either the large amount of data, or the time that the tested tools take up that causes me to suffer, but my question is simple. Is there a way to get around that? I don't get a BMax error, rather the standard MacOS X crash report that appears when a system crash happens inside executable. |
| ||
Ive never been satisfied with TProcess either, mostly i loose data with it. on longer running processes, or processes that rewind their output stream. Im now using popen instead, and havent had any trouble so far. Its not standard posix as far as i know, but even my mingw has it so linux and macosx should too. |
| ||
That 'popen' tool looks interresting. Do you have a BMax adeption of it? (I'm a nitwit when it comes to C or variants of that language) |
| ||
Hello, I'm no expert but something to get you started... Strict Extern Function popen(cmd:Byte Ptr, mode:Byte Ptr) EndExtern Local command:String = "notepad" Local mode:String = "r" Local ptr_cmd:Byte Ptr = command.ToCString() Local ptr_mode:Byte Ptr = mode.ToCString() 'Execute external function popen(ptr_cmd,ptr_mode) 'Free string memory MemFree ptr_cmd MemFree ptr_mode -Henri |
| ||
Ive been using popen from C mostly... but heres some code adapted from one of my projects that does simple read buffering. That should at least get you started :) |
| ||
Thanks a lot guys... I may not be able to put it into my current release of my current project right away (the release preparations were already in a too far stage), but I will definitely see if this code can get me things done in my next release Thanks again ;) |