1. Redirecting input and output from a console

I am creating a GUI interface for a Latin Dictionary programmed in Ada.  Since I
don't know Ada, I want to use the compiled EXE of the dictionary program.
My program currently allows the user to select words in a Latin text to look up
and then calls the dictionary in a console window.  This creates two problems
which I would like to address:
1) The black background and default font of the console window do not mesh with
the smoother Richtext window I load the Latin text in.  2) The dictionary has to
be reloaded for every word by calling "words.exe wordtolookup".
I would like to be able to load the dictionary in the background and have the
dictionary output redirected into a message box or (even better) richtext box,
and it would also be nice to be able to redirect input for the console.
Then I could just have the dictionary running and simulate keyboard entry to
look up a word rather than reloading it from the command line each time.

Any help with redirecting would be appreciated; I am using Euph 2.5 and
win32lib.


Abram Ring

new topic     » topic index » view message » categorize

2. Re: Redirecting input and output from a console

Abram Ring wrote:
> 
> I would like to be able to load the dictionary in the background and have the
> dictionary
> output redirected into a message box or (even better) richtext box, and it
> would also
> be nice to be able to redirect input for the console.
> Then I could just have the dictionary running and simulate keyboard entry to
> look up
> a word rather than reloading it from the command line each time.
> 
> Any help with redirecting would be appreciated; I am using Euph 2.5 and
> win32lib.
> 

I can help with the "any help" bit, but I'm afraid I don't have a firm solution.

In Perl you do this with eg. IPC::open2(rdrfh, wtrfh, "command") then read from
rdrfh, write to wtrfh.  Which is fraught with danger and actively discouraged
in the perl docs.

I looked at doing this in Euphoria and could see no easy way (even with Perl
I ended up using IO::Sockets to talk to a process in a virtual terminal,
open2/open3 was messy with input/output buffering making things difficult).

So the closest I got to it with Euphoria was looking at the native win32
functions, eg CreateProcess ?  But I could not see anything concrete there
relating to file handles.

If you have the time and patience then the win32.hlp SDK file might be worth
a trawl.

Actually, I've just spotted ReadConsole/WriteConsole so it looks like if you
use CreateProcess with the CREATE_NEW_CONSOLE (or DETACHED_PROCESS?) flag 
in dwCreationFlags you would get the console handle returned in the 
lpProcessInformation struct?

Looks like a lot of hard work to me, but hey at least you have language that
makes it possible :)

Gary

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

3. Re: Redirecting input and output from a console

Abram Ring wrote:
> 
> 
> I am creating a GUI interface for a Latin Dictionary programmed in Ada.  Since
> I don't
> know Ada, I want to use the compiled EXE of the dictionary program.
> My program currently allows the user to select words in a Latin text to look
> up and
> then calls the dictionary in a console window.  This creates two problems
> which I would
> like to address:
> 1) The black background and default font of the console window do not mesh
> with the
> smoother Richtext window I load the Latin text in.  2) The dictionary has to
> be reloaded
> for every word by calling "words.exe wordtolookup".
> I would like to be able to load the dictionary in the background and have the
> dictionary
> output redirected into a message box or (even better) richtext box, and it
> would also
> be nice to be able to redirect input for the console.
> Then I could just have the dictionary running and simulate keyboard entry to
> look up
> a word rather than reloading it from the command line each time.
> 
> Any help with redirecting would be appreciated; I am using Euph 2.5 and
> win32lib.
> 
> 
> Abram Ring
> 

Hi there,

Does the exe you are now working with allow say this:

  Lookup.exe "chair"

(and then display the result in the console) ?

Or, better yet, is the exe written in Euphoria where the input/output
methods can be changed to suite and then re-bind'ed ?


Take care,
Al

And, good luck with your Euphoria programming!

My bumper sticker: "I brake for LED's"

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

4. Re: Redirecting input and output from a console

Al Getz wrote:
> 
> Abram Ring wrote:
> > 
> > 
> > I am creating a GUI interface for a Latin Dictionary programmed in Ada. 
> > Since I don't
> > know Ada, I want to use the compiled EXE of the dictionary program.
> > My program currently allows the user to select words in a Latin text to look
> > up and
> > then calls the dictionary in a console window.  This creates two problems
> > which I would
> > like to address:
> > 1) The black background and default font of the console window do not mesh
> > with the
> > smoother Richtext window I load the Latin text in.  2) The dictionary has to
> > be reloaded
> > for every word by calling "words.exe wordtolookup".
> > I would like to be able to load the dictionary in the background and have
> > the dictionary
> > output redirected into a message box or (even better) richtext box, and it
> > would also
> > be nice to be able to redirect input for the console.
> > Then I could just have the dictionary running and simulate keyboard entry to
> > look up
> > a word rather than reloading it from the command line each time.
> > 
> > Any help with redirecting would be appreciated; I am using Euph 2.5 and
> > win32lib.
> > 
> > 
> > Abram Ring
> > 
> 
> Hi there,
> 
> Does the exe you are now working with allow say this:
> 
>   Lookup.exe "chair"
> 
> (and then display the result in the console) ?
> 
> Or, better yet, is the exe written in Euphoria where the input/output
> methods can be changed to suite and then re-bind'ed ?
> 
> 
> Take care,
> Al
> 
> And, good luck with your Euphoria programming!
> 
> My bumper sticker: "I brake for LED's"
> 


The EXE can be invoked by "words.exe animus" to show the definition of "animus"
in a console window.
I can set the EXE to output to a file and then read the file into a Richtext
window.  My problem now is that when I shell to call the EXE with system() and
then load the output file, everything works.
However, when I use shellExecuteEx() so that I can hide console window which
pops up, the richtext window always shows the previous word looked up rather than
the word just selected.
Since there has been no change in the code other than replacing the system()
call with shellExecuteEx(), I suspect that somehow the shellExecuteEx() call is
not finished invoking the dictionary EXE before my program goes on to load the
output file.
In other words, I suspect system() suspends other activity until finished,
whereas shellExecuteEx() runs concurrently with the following code.
Does this seem right?  I am new to Windows programming.  Perhaps, I need to
somehow to have my program wait for the shellExecuteEx() process to complete.

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

5. Re: Redirecting input and output from a console

Hi Abram,


Did you try opening a console (like with say ?"") and then
minimizing the console?  This works pretty well sometimes.
You're dealing with the same console for all lookups so
it's a bit easier to handle and you can still use system().

A better idea might be to get the source code for your
exe program (words.exe) and create a new version based on
the Euphoria language.  This way you have complete control
over everything.  I did a word speller program like this
once which also uses a RichEdit for both input and output.

How big is that words.exe program file?


Take care,
Al

And, good luck with your Euphoria programming!

My bumper sticker: "I brake for LED's"

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

6. Re: Redirecting input and output from a console

On Thu, 07 Jul 2005 10:08:32 -0700, Abram Ring
<guest at RapidEuphoria.com> wrote:

>I can set the EXE to output to a file and then read the file into a Richtext
>window.  My problem now is that when I shell to call the EXE with system() and
>then load the output file, everything works.
>However, when I use shellExecuteEx() so that I can hide console window which
>pops up, the richtext window always shows the previous word looked up rather than
>the word just selected.
>Since there has been no change in the code other than replacing the system()
>call with shellExecuteEx(), I suspect that somehow the shellExecuteEx() call is
>not finished invoking the dictionary EXE before my program goes on to load the
>output file.
>In other words, I suspect system() suspends other activity until finished,
>whereas shellExecuteEx() runs concurrently with the following code.
>Does this seem right?  I am new to Windows programming.  Perhaps, I need to
>somehow to have my program wait for the shellExecuteEx() process to complete.

Have a look at system_wait in the archives. After:
   poke4(si+cb, SIZEOF_STARTUPINFO)
you might want to try:
poke(si+wShowWindow, SW_HIDE)

(NB untested, you'll have to uncomment wShowWindow as well).

Regards,
Pete

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

7. Re: Redirecting input and output from a console

> >I can set the EXE to output to a file and then read the file into a Richtext
> >window.  My problem now is that when I
shell to call the EXE with system() and then load the output file, everything
works.
> >However, when I use shellExecuteEx() so that I can hide console window which
> >pops up, the richtext window always
shows the previous word looked up rather than the word just selected.
> >Since there has been no change in the code other than replacing the system()
> >call with shellExecuteEx(), I suspect
that somehow the shellExecuteEx() call is not finished invoking the dictionary
EXE before my program goes on to load the
output file.
> >In other words, I suspect system() suspends other activity until finished,
> >whereas shellExecuteEx() runs concurrently
with the following code.

Why not simply delete the output file after every read.
This will permit you to create a read loop, also using sleep().
( if file can't be opened, then wait, and try again )
If sleep(1) granularity seems too long, just 'wrap' the API's sleep(), which
will give millisecond granularity.
 ...well, um, maybe 20 millisecond... )

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

Search



Quick Links

User menu

Not signed in.

Misc Menu