comp.lang.ada
 help / color / mirror / Atom feed
* Start a Windows process and get its text output
@ 2010-02-06 17:39 Gautier write-only
  2010-02-06 18:12 ` Hibou57 (Yannick Duchêne)
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Gautier write-only @ 2010-02-06 17:39 UTC (permalink / raw)


Hello,

Does someone have some nice open source to do that ?
I began to cannibalize working code from AdaGIDE, but it is a bit
messy.
If I can save a couple of hours to make a good package out of it, it
would be cool...
TIA

[ the goal is to have a reusable object-oriented component; its first
usage would be in the GWenerator tool for launching gnatmake or a
resource compiler and display its output in boxes ]
______________________________________________________________
Gautier's Ada programming -- http://gautiersblog.blogspot.com/



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Start a Windows process and get its text output
  2010-02-06 17:39 Start a Windows process and get its text output Gautier write-only
@ 2010-02-06 18:12 ` Hibou57 (Yannick Duchêne)
  2010-02-06 18:23 ` Pascal Obry
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 11+ messages in thread
From: Hibou57 (Yannick Duchêne) @ 2010-02-06 18:12 UTC (permalink / raw)


On 6 fév, 18:39, Gautier write-only <gautier_niou...@hotmail.com>
wrote:
> Hello,
>
> Does someone have some nice open source to do that ?
> I began to cannibalize working code from AdaGIDE, but it is a bit
> messy.
> If I can save a couple of hours to make a good package out of it, it
> would be cool...
> TIA
>
> [ the goal is to have a reusable object-oriented component; its first
> usage would be in the GWenerator tool for launching gnatmake or a
> resource compiler and display its output in boxes ]
> ______________________________________________________________
> Gautier's Ada programming --http://gautiersblog.blogspot.com/

Funny coincidence, I'm currently working on such a thing for a Windows
API binding.
But as you guess, my concern is not only about running a process and
getting its output, it is also integration and overall design of my
set of packages, and other experiencing and personal requirements.

I was not really to provide these packages open source, but I may, as
a special exception, grant you this subset (I would have to setup this
subset by the way) under a two clause BSD license. Let say this may be
useful to me, to get some feedback in return.

Just tell me : are you on a hurry or can you manage you timing easily
large ? Tell me about your timing.

Reply to me either here, or via my e-mail at you option.

Note : I'm not targeting Windows 95/98 for the moment, for Unicode
support reason (it is planned, but gonna be a pain, I have reasons to
know this). I want all my binding to be strictly Unicode. Is it a
potential issue for you ?



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Start a Windows process and get its text output
  2010-02-06 17:39 Start a Windows process and get its text output Gautier write-only
  2010-02-06 18:12 ` Hibou57 (Yannick Duchêne)
@ 2010-02-06 18:23 ` Pascal Obry
  2010-02-06 19:21   ` Gautier write-only
  2010-02-06 19:42 ` Jeffrey R. Carter
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Pascal Obry @ 2010-02-06 18:23 UTC (permalink / raw)


Le 06/02/2010 18:39, Gautier write-only a �crit :
> Hello,
> 
> Does someone have some nice open source to do that ?

What about GNAT.Expect?

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|    http://www.obry.net  -  http://v2p.fr.eu.org
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver keys.gnupg.net --recv-key F949BD3B




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Start a Windows process and get its text output
  2010-02-06 18:23 ` Pascal Obry
@ 2010-02-06 19:21   ` Gautier write-only
  0 siblings, 0 replies; 11+ messages in thread
From: Gautier write-only @ 2010-02-06 19:21 UTC (permalink / raw)


On Feb 6, 7:23 pm, Pascal Obry <pas...@obry.net> wrote:

> What about GNAT.Expect?

Thanks, it looks exactly what I need. Just need to use it correctly.
Fortunately there is an example there:
http://www.adacore.com/2008/11/24/gem-54/
Just need to find how pipe the process' output to a string buffer.
An idea ? I guess it is a 1-liner with GNAT.Expect.
Thanks again
_________________________________________________________
Gautier's Ada programming -- http://sf.net/users/gdemont/
NB: For a direct answer, e-mail address on the Web site!



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Start a Windows process and get its text output
  2010-02-06 17:39 Start a Windows process and get its text output Gautier write-only
  2010-02-06 18:12 ` Hibou57 (Yannick Duchêne)
  2010-02-06 18:23 ` Pascal Obry
@ 2010-02-06 19:42 ` Jeffrey R. Carter
  2010-02-06 21:01 ` Dmitry A. Kazakov
  2010-02-07 17:54 ` Vadim Godunko
  4 siblings, 0 replies; 11+ messages in thread
From: Jeffrey R. Carter @ 2010-02-06 19:42 UTC (permalink / raw)


Gautier write-only wrote:
> 
> Does someone have some nice open source to do that ?
> I began to cannibalize working code from AdaGIDE, but it is a bit
> messy.
> If I can save a couple of hours to make a good package out of it, it
> would be cool...

I used to do something like this to get a directory listing in Ada 95: Using 
GNAT.OS_Lib I spawned cmd and redirected the output to a file, then read the 
file from my program. Not nearly as complex as what you're after, but it worked 
for my purposes and only took a few minutes to get working.

-- 
Jeff Carter
"It's symbolic of his struggle against reality."
Monty Python's Life of Brian
78



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Start a Windows process and get its text output
  2010-02-06 17:39 Start a Windows process and get its text output Gautier write-only
                   ` (2 preceding siblings ...)
  2010-02-06 19:42 ` Jeffrey R. Carter
@ 2010-02-06 21:01 ` Dmitry A. Kazakov
  2010-02-07 17:54 ` Vadim Godunko
  4 siblings, 0 replies; 11+ messages in thread
From: Dmitry A. Kazakov @ 2010-02-06 21:01 UTC (permalink / raw)


On Sat, 6 Feb 2010 09:39:30 -0800 (PST), Gautier write-only wrote:

> Does someone have some nice open source to do that ?
> I began to cannibalize working code from AdaGIDE, but it is a bit
> messy.
> If I can save a couple of hours to make a good package out of it, it
> would be cool...
> TIA
> 
> [ the goal is to have a reusable object-oriented component; its first
> usage would be in the GWenerator tool for launching gnatmake or a
> resource compiler and display its output in boxes ]

For same purpose (launching gprbuild and catching the output and error
streams) I used GTK+ bindings.

I considered GNAT.OS_Lib, but dropped that for various reasons. Since GTK+
API are quite tricky when it comes to process spawning, I built thicker
bindings on top. Spawning a process with pipes:

   http://www.dmitry-kazakov.de/ada/gtkada_contributions.htm#10.1

and with text buffers instead of pipes

   http://www.dmitry-kazakov.de/ada/gtkada_contributions.htm#10.2

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Start a Windows process and get its text output
  2010-02-06 17:39 Start a Windows process and get its text output Gautier write-only
                   ` (3 preceding siblings ...)
  2010-02-06 21:01 ` Dmitry A. Kazakov
@ 2010-02-07 17:54 ` Vadim Godunko
  2010-02-07 19:24   ` Hibou57 (Yannick Duchêne)
  4 siblings, 1 reply; 11+ messages in thread
From: Vadim Godunko @ 2010-02-07 17:54 UTC (permalink / raw)


On Feb 6, 8:39 pm, Gautier write-only <gautier_niou...@hotmail.com>
wrote:
> Hello,
>
> Does someone have some nice open source to do that ?
QProcess class from Qt (and QtAda) can be used for that.



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Start a Windows process and get its text output
  2010-02-07 17:54 ` Vadim Godunko
@ 2010-02-07 19:24   ` Hibou57 (Yannick Duchêne)
  2010-02-07 19:36     ` Hibou57 (Yannick Duchêne)
                       ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Hibou57 (Yannick Duchêne) @ 2010-02-07 19:24 UTC (permalink / raw)


As it is the subject here : I've just checked at least with GNAT it
work nice to create a task, invok a CreateProcess from this Ada task
and then WaitForSingleObject with delay INFINITE on the process handle
always in the same Ada task : other Ada task are still running
normally (a protected object can then be used to tell any other task
the process has terminated).

I was wondering about the cost of threads on Windows, as GNAT create
Ada task as Windows thread (I suppose its the same for Janus and
others, I hope to be honest). I just found there is a default
allocated stack of 1M bytes, and nothing about the cost of task
creation and task switch in CPU cycles (from a pure point of view,
dropping any page fault and the like). If someone know a good source
about it, it would be nice (this is to weigh up the choice to have an
Ada task per process vs. a single Ada task managing multiple
processes).

The sole words about it in the MS reference says :
> The number of threads a process can create is limited by the
> available virtual memory. By default, every thread has one megabyte
> of stack space. Therefore, you can create at most 2028 threads. If
> you reduce the default stack size, you can create more threads.
> However, your application will have better performance if you create
> one thread per processor and build queues of requests for which the
> application maintains the context information. A thread would
> process all requests in a queue before processing requests in the
> next queue.

While the thread (then Ada task) stack size can be tuned with the
Storage_Size attribute, while formally speaking, as of [ARM 13.1(60)],
this is not strictly the stack size, but rather a size including the
stack size. And this attribute is marked as obsolescent in [ARM J.6],
in favor of the pragma which as the same name.



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Start a Windows process and get its text output
  2010-02-07 19:24   ` Hibou57 (Yannick Duchêne)
@ 2010-02-07 19:36     ` Hibou57 (Yannick Duchêne)
  2010-02-07 20:35     ` Hibou57 (Yannick Duchêne)
  2010-02-07 21:36     ` Dmitry A. Kazakov
  2 siblings, 0 replies; 11+ messages in thread
From: Hibou57 (Yannick Duchêne) @ 2010-02-07 19:36 UTC (permalink / raw)


On 7 fév, 20:24, Hibou57 (Yannick Duchêne) <yannick_duch...@yahoo.fr>
wrote:
> stack size. And this attribute is marked as obsolescent in [ARM J.6],
> in favor of the pragma which as the same name.
Oops : this is obviously Annexe J.9 (not J.6)



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Start a Windows process and get its text output
  2010-02-07 19:24   ` Hibou57 (Yannick Duchêne)
  2010-02-07 19:36     ` Hibou57 (Yannick Duchêne)
@ 2010-02-07 20:35     ` Hibou57 (Yannick Duchêne)
  2010-02-07 21:36     ` Dmitry A. Kazakov
  2 siblings, 0 replies; 11+ messages in thread
From: Hibou57 (Yannick Duchêne) @ 2010-02-07 20:35 UTC (permalink / raw)


On 7 fév, 20:24, Hibou57 (Yannick Duchêne) <yannick_duch...@yahoo.fr>
wrote:
> I was wondering about the cost of threads on Windows, as GNAT create
> Ada task as Windows thread (I suppose its the same for Janus and
> others, I hope to be honest).
> [...]
>
> The sole words about it in the MS reference says :
For any interested parties, I've found an answer which seems
reasonable here :
http://stackoverflow.com/questions/304752/how-to-estimate-the-thread-context-switching-overhead

Two interesting quotes are:

> Oh, and I remember an application running on Windows CE 4.X, where
> we also have four threads with intensive switching at times, and
> never ran into performance issues.

and

> Output
> Number of thread switches in about one second was 108406
> Over 100'000 is not too bad and that even though we have locking and
> conditional waits. I'd guess without all this stuff at least twice
> as many thread switches were possible a second.

Threads does not cost so much after all (keep in mind this was on
architecture with support for Windows, this is Windows specific).



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Start a Windows process and get its text output
  2010-02-07 19:24   ` Hibou57 (Yannick Duchêne)
  2010-02-07 19:36     ` Hibou57 (Yannick Duchêne)
  2010-02-07 20:35     ` Hibou57 (Yannick Duchêne)
@ 2010-02-07 21:36     ` Dmitry A. Kazakov
  2 siblings, 0 replies; 11+ messages in thread
From: Dmitry A. Kazakov @ 2010-02-07 21:36 UTC (permalink / raw)


On Sun, 7 Feb 2010 11:24:41 -0800 (PST), Hibou57 (Yannick Duch�ne) wrote:

> As it is the subject here : I've just checked at least with GNAT it
> work nice to create a task, invok a CreateProcess from this Ada task
> and then WaitForSingleObject with delay INFINITE on the process handle
> always in the same Ada task : other Ada task are still running
> normally (a protected object can then be used to tell any other task
> the process has terminated).

You can use WaitForSingleObject in order to determine if the object (like
the process) is signaled without waiting. (Do not forget to close the
object handle when you don't need it.)

> I was wondering about the cost of threads on Windows, as GNAT create
> Ada task as Windows thread (I suppose its the same for Janus and
> others, I hope to be honest). I just found there is a default
> allocated stack of 1M bytes, and nothing about the cost of task
> creation and task switch in CPU cycles (from a pure point of view,

The cost of switching depends on the processor. I remember that it was very
high for x86 in earlier times. I cannot tell if it is still so.

But I think you can measure it. Start several tasks incrementing a counter
in a loop. A Windows call Delay (0) should switch the task prematurely. Do
that each, say 100_000 increments (it must be shorter than 1ms, otherwise
Windows scheduler will intervene). Run this until the sum of counters
reaches some value. Do the same with one task. The time difference divided
by the number of switches is the task switching overhead.

> dropping any page fault and the like). If someone know a good source
> about it, it would be nice (this is to weigh up the choice to have an
> Ada task per process vs. a single Ada task managing multiple
> processes).

The latter will not work in most cases because of blocking I/O. Well, there
is overlapped I/O API under Windows, but you would need to rewrite all code
for this, and not all (a minority in fact) devices support overlapped I/O.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2010-02-07 21:36 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-06 17:39 Start a Windows process and get its text output Gautier write-only
2010-02-06 18:12 ` Hibou57 (Yannick Duchêne)
2010-02-06 18:23 ` Pascal Obry
2010-02-06 19:21   ` Gautier write-only
2010-02-06 19:42 ` Jeffrey R. Carter
2010-02-06 21:01 ` Dmitry A. Kazakov
2010-02-07 17:54 ` Vadim Godunko
2010-02-07 19:24   ` Hibou57 (Yannick Duchêne)
2010-02-07 19:36     ` Hibou57 (Yannick Duchêne)
2010-02-07 20:35     ` Hibou57 (Yannick Duchêne)
2010-02-07 21:36     ` Dmitry A. Kazakov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox