1. Windows Console Output

How do I capture Windows console output from euphoria.
senario:
    * lauch the console app useing system()
    * capture it's console output

I want to be able to redirect output to a file but I would prefer to capture the
output into a sequence for preccess, then do the file i/o myself

new topic     » topic index » view message » categorize

2. Re: Windows Console Output

Hi Hayden,
If the console app you launch is one that you build yourself in euphoria, then
the following procedure would do it.
1) in main application create a named pipe for reading.
2) launch the child app.
3) child app. open the named pipe for writing
4) child app. send all its input to the pipe.
5) child close pipe.
6) child exit.
The name of the pipe can be coded in parent and child app if they are build to
always work together or the child app can be designed to receive the name of the
pipe from its command line arguments.
This work as well with console as with gui application.

The windows api for pipes is quite simple:
http://msdn2.microsoft.com/en-us/library/aa365781.aspx

My watch-svr/watch-client debug tool use such a system but it use a mailslot
which is a oneway multi-client named pipe.
Looking at it can give you some ideas:
http://www.rapideuphoria.com/watch-svr.zip

regards,
Jacques Deschênes

new topic     » goto parent     » topic index » view message » categorize

3. Re: Windows Console Output

I just realize that you can use pipe in that context as system() only reurn when
the child process as ended.
But why don't you use somthing like system("console_app > temp_file",2)
then the main application open and read the data in the temp_file.



jacques deschênes wrote:
> 
> 
> Hi Hayden,
> If the console app you launch is one that you build yourself in euphoria, then
> the following procedure would do it.
> 1) in main application create a named pipe for reading.
> 2) launch the child app.
> 3) child app. open the named pipe for writing
> 4) child app. send all its input to the pipe.
> 5) child close pipe.
> 6) child exit.
> The name of the pipe can be coded in parent and child app if they are build
> to always work together or the child app can be designed to receive the name
> of the pipe from its command line arguments.
> This work as well with console as with gui application.
> 
> The windows api for pipes is quite simple: <a
> href="http://msdn2.microsoft.com/en-us/library/aa365781.aspx">http://msdn2.microsoft.com/en-us/library/aa365781.aspx</a>
> 
> My watch-svr/watch-client debug tool use such a system but it use a mailslot
> which is a oneway multi-client named pipe.
> Looking at it can give you some ideas: <a
> href="http://www.rapideuphoria.com/watch-svr.zip">http://www.rapideuphoria.com/watch-svr.zip</a>
> 
> regards,
> Jacques Deschênes

new topic     » goto parent     » topic index » view message » categorize

4. Re: Windows Console Output

jacques deschênes wrote:
> 
> 
> Hi Hayden,
> If the console app you launch is one that you build yourself in euphoria, then
> the following procedure would do it.

< snip >

no, the console app is in some other language. it's open source so maybee i
could modify then recomile but it would be better for me just to capture the
output and proccess it with euphoria.

BTW, thanks for link to CreatePipe() stuff

new topic     » goto parent     » topic index » view message » categorize

5. Re: Windows Console Output

As I often use console command at work, usualy I send the output of the command
to a file then I use an euphoria script to extract the information from that
file.
example:
net view > net_view.txt
exwc xtract_hosts_names.exw net_view.txt hosts.txt

For a long time I have been thinking about writing a library to capture console
i/o but never took the time to do it.
But from you question I made some search on MSDN and found a C sample code that
show how to do it and decided to write capture.e
the interface would look something like it.
fnVal = CaptureRun(sequence command_arg,integer Option)
command_arg should be a string with the command and its arguments
Option should be one or more of  CAPTURE_STDIN, CAPTURE_STDOUT, CAPTURE_STDERR
ored togethers.
fnVal would be Process Information in a sequence or -1 if CaptureRun failed
Contrary to system() or system_exec()  CaptureRun() will return immediately
So a dialog could be engaged between the parent process and the child process.

jacques d.


Hayden McKay wrote:
> 
> jacques deschênes wrote:
> > 
> > 
> > Hi Hayden,
> > If the console app you launch is one that you build yourself in euphoria,
> > then
> > the following procedure would do it.
> 
> < snip >
> 
> no, the console app is in some other language. it's open source so maybee i
> could modify then recomile but it would be better for me just to capture the
> output and proccess it with euphoria.
> 
> BTW, thanks for link to CreatePipe() stuff

new topic     » goto parent     » topic index » view message » categorize

6. Re: Windows Console Output

jacques deschênes wrote:
> 
> As I often use console command at work, usualy I send the output of the
> command
> to a file then I use an euphoria script to extract the information from that
> file.
> example:
> net view > net_view.txt
> exwc xtract_hosts_names.exw net_view.txt hosts.txt
> 
> For a long time I have been thinking about writing a library to capture
> console
> i/o but never took the time to do it.
> But from you question I made some search on MSDN and found a C sample code
> that
> show how to do it and decided to write capture.e
> the interface would look something like it.
> fnVal = CaptureRun(sequence command_arg,integer Option)
> command_arg should be a string with the command and its arguments
> Option should be one or more of  CAPTURE_STDIN, CAPTURE_STDOUT, CAPTURE_STDERR
> ored togethers.
> fnVal would be Process Information in a sequence or -1 if CaptureRun failed
> Contrary to system() or system_exec()  CaptureRun() will return immediately
> So a dialog could be engaged between the parent process and the child process.
> 
> jacques d.
> 
> 
> Hayden McKay wrote:
> > 
> > jacques deschênes wrote:
> > > 
> > > 
> > > Hi Hayden,
> > > If the console app you launch is one that you build yourself in euphoria,
> > > then
> > > the following procedure would do it.
> > 
> > < snip >
> > 
> > no, the console app is in some other language. it's open source so maybee i
> > could modify then recomile but it would be better for me just to capture the
> > output and proccess it with euphoria.
> > 
> > BTW, thanks for link to CreatePipe() stuff

  Hello jacques,

I too am very interested in this. As I would like to convert the console
  window to a text file for printing purposes. If posible I would like to see the
  complete code in Euphoria of course. I don't know much about C.


Don Cole

new topic     » goto parent     » topic index » view message » categorize

7. Re: Windows Console Output

jacques deschênes wrote:
> For a long time I have been thinking about writing a library to capture 
> console i/o but never took the time to do it.
> But from you question I made some search on MSDN and found a C sample code 
> that show how to do it and decided to write capture.e

There is some code in Edita which attempts to capture console output,
specifically in eacons.ew and eacons.exw. As a disclaimer, it is squarely aimed
at running Eu source code via exwc.exe and is less than 100% perfect.

What I did find (on win98) is that I needed a separate process (eacons.exw) to
be the sacrificial lamb that locks up, with eacons.ew looking after it and
sending it a wakeup/die message. Feel free to steal/ignore any of that.

Regards,
Pete

new topic     » goto parent     » topic index » view message » categorize

8. Re: Windows Console Output

don cole wrote:
> 
> jacques deschênes wrote:
> > 
> > As I often use console command at work, usualy I send the output of the
> > command
> > to a file then I use an euphoria script to extract the information from that
> > file.
> > example:
> > net view > net_view.txt
> > exwc xtract_hosts_names.exw net_view.txt hosts.txt
> > 
> > For a long time I have been thinking about writing a library to capture
> > console
> > i/o but never took the time to do it.
> > But from you question I made some search on MSDN and found a C sample code
> > that
> > show how to do it and decided to write capture.e
> > the interface would look something like it.
> > fnVal = CaptureRun(sequence command_arg,integer Option)
> > command_arg should be a string with the command and its arguments
> > Option should be one or more of  CAPTURE_STDIN, CAPTURE_STDOUT,
> > CAPTURE_STDERR
> > ored togethers.
> > fnVal would be Process Information in a sequence or -1 if CaptureRun failed
> > Contrary to system() or system_exec()  CaptureRun() will return immediately
> > So a dialog could be engaged between the parent process and the child
> > process.
> > 
> > jacques d.
> > 
> > 
> > Hayden McKay wrote:
> > > 
> > > jacques deschênes wrote:
> > > > 
> > > > 
> > > > Hi Hayden,
> > > > If the console app you launch is one that you build yourself in
> > > > euphoria, then
> > > > the following procedure would do it.
> > > 
> > > < snip >
> > > 
> > > no, the console app is in some other language. it's open source so maybee
> > > i
> > > could modify then recomile but it would be better for me just to capture
> > > the
> > > output and proccess it with euphoria.
> > > 
> > > BTW, thanks for link to CreatePipe() stuff
> 
>   Hello jacques,
> 
>   I too am very interested in this. As I would like to convert the console
>   window
> to a text file for printing purposes. If posible I would like to see the
> complete
> code in Euphoria of course. I don't know much about C.
> 
> 
> Don Cole

I spent many hours today working on capture.ew  its almost done. I should be
able to post it to rapideuphoria.com  before monday.
let to be done: code cleanup and testing

features:
- 100% euphoria code
- can capture child process stdin (main process can pipe output to its child
handle 0)
- can capture child process stdout (main process capture child console output
sent to hamdle 1)
- can capture child process stderr (main process capture child error messages
sent to handle 2)
- can capture any combination of 3 above.
- very simple interface
-   capture_exec(cmd_line,option)
-   capture_gets(handle)
-   capture_puts(handle, object data)
-   capture_terminate()

regards,
Jacques Deschênes

new topic     » goto parent     » topic index » view message » categorize

9. Re: Windows Console Output

On 9/22/07, Pete Lomax <guest at rapideuphoria.com> wrote:
>
> There is some code in Edita which attempts to capture console output,
> specifically in eacons.ew and eacons.exw. As a disclaimer, it is squarely aimed
> at running Eu source code via exwc.exe and is less than 100% perfect.
>
> What I did find (on win98) is that I needed a separate process (eacons.exw) to
> be the sacrificial lamb that locks up, with eacons.ew looking after it and
> sending it a wakeup/die message. Feel free to steal/ignore any of that.

I've toiled over this code for hours on end, mashing and mushing it
into an independent include file, that uses dll.e and would be
compatible with any library. The problem was, I could never get it to
work properly. It kept throwing machine level exceptions at me. So I
just gave up. I still have the code around somewhere if anyone's
interested.

-Greg

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu