comp.lang.ada
 help / color / mirror / Atom feed
* not really an Ada question
@ 2000-02-15  0:00 Ehud Lamm
  2000-02-16  0:00 ` Robert Dewar
  2000-02-17  0:00 ` not really an Ada question (long answer) DuckE
  0 siblings, 2 replies; 7+ messages in thread
From: Ehud Lamm @ 2000-02-15  0:00 UTC (permalink / raw)


This is really about Winodws programming, but I do hope someone created a
simple free binding for what I need - so it is not completly off topic.

If I start a program using "sytem" than if the program is windows abes, it
start and I can continue to issue a second "system" call. However,
naturally, if the program invoked is a DOS program (or console? I am nost
sure) my main program waits.

I tried replacing "system" with spawnl, but it didn't work as I expected -
actuaally the second invocation return an error. 

What I wan in essence is a consitent way to invoke any kind of program
(exe file), in a process of its own - even in its own window is ok. The
calling program must be unaffected by this.

A solution based on using "system" from two Ada tasks works like a charm,
but I don't wna this part of the program to be task based. I want to use
the OS multiprogramming facilites. 
Any simple code that does this?

(GNAT3.11 on Win95)

Thakns

Ehud Lamm mslamm@mscc.huji.ac.il
http://purl.oclc.org/NET/ehudlamm <== My home on the web 
Check it out and subscribe to the E-List- for interesting essays and more!






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

* Re: not really an Ada question
  2000-02-15  0:00 not really an Ada question Ehud Lamm
@ 2000-02-16  0:00 ` Robert Dewar
  2000-02-16  0:00   ` Ehud Lamm
  2000-02-17  0:00 ` not really an Ada question (long answer) DuckE
  1 sibling, 1 reply; 7+ messages in thread
From: Robert Dewar @ 2000-02-16  0:00 UTC (permalink / raw)


In article
<Pine.A41.3.96-heb-2.07.1000215155013.63302B-100000@pluto.mscc.h
uji.ac.il>,
  Ehud Lamm <mslamm@mscc.huji.ac.il> wrote:
> What I wan in essence is a consitent way to invoke any kind of
program
> (exe file), in a process of its own - even in its own window
is ok. The
> calling program must be unaffected by this.


Why doesn't GNAT.OS_Lib.Spawn do the job (don't overlook the
stuff in GNAT.*, there is useful stuff there :-)


Sent via Deja.com http://www.deja.com/
Before you buy.




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

* Re: not really an Ada question
  2000-02-16  0:00 ` Robert Dewar
@ 2000-02-16  0:00   ` Ehud Lamm
  2000-02-16  0:00     ` Ehud Lamm
  0 siblings, 1 reply; 7+ messages in thread
From: Ehud Lamm @ 2000-02-16  0:00 UTC (permalink / raw)


On Wed, 16 Feb 2000, Robert Dewar wrote:

|In article
|<Pine.A41.3.96-heb-2.07.1000215155013.63302B-100000@pluto.mscc.h
|uji.ac.il>,
|Ehud Lamm <mslamm@mscc.huji.ac.il> wrote:
|> What I wan in essence is a consitent way to invoke any kind of
|program
|> (exe file), in a process of its own - evenin its own window
|is ok. The
|> calling program must be unaffected by this.
|
|
|Why doesn't GNAT.OS_Lib.Spawn do the job (don't overlook the
|stuff in GNAT.*, there is useful stuff there :-)
|

funny. I am a great fan of the GNAT.* packages. Strange I didn't think of
checking there this time! I will, now!

Thanks.

Ehud Lamm mslamm@mscc.huji.ac.il
http://purl.oclc.org/NET/ehudlamm <== My home on the web 
Check it out and subscribe to the E-List- for interesting essays and more!







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

* Re: not really an Ada question
  2000-02-16  0:00   ` Ehud Lamm
@ 2000-02-16  0:00     ` Ehud Lamm
  2000-02-17  0:00       ` Charles Hixson
  2000-02-17  0:00       ` Robert A Duff
  0 siblings, 2 replies; 7+ messages in thread
From: Ehud Lamm @ 2000-02-16  0:00 UTC (permalink / raw)


On Wed, 16 Feb 2000, Ehud Lamm wrote:

|On Wed, 16 Feb 2000, Robert Dewar wrote:
|
||Why doesn't GNAT.OS_Lib.Spawn do the job (don't overlook the
||stuff in GNAT.*, there is useful stuff there :-)
||
|
|funny. I am a great fan of the GNAT.* packages. Strange I didn't think of
|checking there this time! I will, now!

Well I tried using non_Blocking_Spawn - as this seems the thing I want,
right? I want the next spawn to work in such a way that the two programs
will work side by side.

Well this is not what happens.

To be concrete: the program I execute is a simple prgram create using
GNAT, toom that loops printing a word to the screen and delaying. 

I am pretty sure the issue here is how Windows works, not Ada - but any
clue will be recieved gratefully.

Ehud Lamm mslamm@mscc.huji.ac.il
http://purl.oclc.org/NET/ehudlamm <== My home on the web 
Check it out and subscribe to the E-List- for interesting essays and more!







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

* Re: not really an Ada question
  2000-02-16  0:00     ` Ehud Lamm
  2000-02-17  0:00       ` Charles Hixson
@ 2000-02-17  0:00       ` Robert A Duff
  1 sibling, 0 replies; 7+ messages in thread
From: Robert A Duff @ 2000-02-17  0:00 UTC (permalink / raw)


Ehud Lamm <mslamm@mscc.huji.ac.il> writes:

> Well I tried using non_Blocking_Spawn - as this seems the thing I want,
> right? I want the next spawn to work in such a way that the two programs
> will work side by side.
> 
> Well this is not what happens.

I suggest you read the code for the body of this package, and the C code
it ends up calling.  If I recall, it doesn't work quite the same way on
all targets.

- Bob




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

* Re: not really an Ada question
  2000-02-16  0:00     ` Ehud Lamm
@ 2000-02-17  0:00       ` Charles Hixson
  2000-02-17  0:00       ` Robert A Duff
  1 sibling, 0 replies; 7+ messages in thread
From: Charles Hixson @ 2000-02-17  0:00 UTC (permalink / raw)


What are you doing in the spawned (ok, not task) process?  If I remember
correctly, whenever Win95 calls on a 16-bit system routine, it goes into
single executable thread mode... I'm a bit vague on the details here
(answering my question won't mean much to me!), but I am sure that there is
only one 16-bit thread, that is shared by all of the 16-bit processes that are
running.  So you could easily be colliding with yourself if you make any
system calls.

Ehud Lamm wrote:

> On Wed, 16 Feb 2000, Ehud Lamm wrote:
>
> |On Wed, 16 Feb 2000, Robert Dewar wrote:
> |
> ||Why doesn't GNAT.OS_Lib.Spawn do the job (don't overlook the
> ||stuff in GNAT.*, there is useful stuff there :-)
> ||
> |
> |funny. I am a great fan of the GNAT.* packages. Strange I didn't think of
> |checking there this time! I will, now!
>
> Well I tried using non_Blocking_Spawn - as this seems the thing I want,
> right? I want the next spawn to work in such a way that the two programs
> will work side by side.
>
> Well this is not what happens.
>
> To be concrete: the program I execute is a simple prgram create using
> GNAT, toom that loops printing a word to the screen and delaying.
>
> I am pretty sure the issue here is how Windows works, not Ada - but any
> clue will be recieved gratefully.
>
> Ehud Lamm mslamm@mscc.huji.ac.il
> http://purl.oclc.org/NET/ehudlamm <== My home on the web
> Check it out and subscribe to the E-List- for interesting essays and more!





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

* Re: not really an Ada question (long answer)
  2000-02-15  0:00 not really an Ada question Ehud Lamm
  2000-02-16  0:00 ` Robert Dewar
@ 2000-02-17  0:00 ` DuckE
  1 sibling, 0 replies; 7+ messages in thread
From: DuckE @ 2000-02-17  0:00 UTC (permalink / raw)


Windows NT (and Windows 95) prefer "CreateProcess" for creating another
process. I have
attached an example I put together quite a while back for NT.

In this particular example I start up a process to act as a slave to the
calling program.  The stdin, stdout, and stderror files are mapped to pipes
used to drive the process.

While this isn't exactly what you asked for, it does give a working example
of the use of "CreateProcess", which is I believe what you need.  The code
does rely on the Win32Ada binding.

SteveD

==== Launch.adb ====
WITH Win32;
WITH Win32.WinBase;
WITH Win32.WinNT;
WITH System;
WITH Interfaces.C;
 USE Interfaces.C;
WITH Interfaces.C.Strings;
 USE Interfaces.C.Strings;
WITH Ada.Text_Io;

WITH NTSntServerProcess;
 USE NTSntServerProcess;

PROCEDURE Launch IS

  PACKAGE WinBase RENAMES Win32.WinBase;
  PACKAGE WinNT RENAMES Win32.WinNT;
  PACKAGE Text_Io RENAMES Ada.Text_Io;
  USE TYPE Win32.BOOL;

  result : Win32.BOOL;
  stdInLocHandle   : ALIASED WinNT.HANDLE;
  stdOutLocHandle  : ALIASED WinNT.HANDLE;
  stdErrLocHandle  : ALIASED WinNT.HANDLE;

  inputBuffer : CHAR_ARRAY(0..255);
  bytesRead   : ALIASED Win32.DWORD;

BEGIN
  CreateSubprocessNTS( commandDirNTS  => "",
                       commandLineNTS => "c:\csrc\hello.exe",
                       workDirNTS     => "c:\csrc",
                       windowNameNTS  => "Window name",
                       stdInNTS       => stdInLocHandle,
                       stdOutNTS      => stdOutLocHandle,
                       stdErrNTS      => stdErrLocHandle );


  Text_Io.Put_Line( "=== Start of output ===" );
  LOOP
    result := WinBase.ReadFile( stdOutLocHandle,
                                inputBuffer(0)'ADDRESS,
                                Win32.DWORD( 2 ), -- inputBuffer'LENGTH ),
                                bytesRead'UNCHECKED_ACCESS,
                                NULL );
    EXIT WHEN result <= 0;

    Text_Io.Put( To_Ada( inputBuffer )(1..Integer( bytesRead ) ) );
  END LOOP;
  Text_Io.Put_Line( "=== End of output ===" );

  Text_Io.Put_Line( "Result = " & Win32.BOOL'IMAGE( result ) );

  CloseFilesNTS( stdOutLocHandle, stdOutLocHandle, stdErrLocHandle );

--  result := WinBase.CloseHandle( stdInProcHandle );
--  result := WinBase.CloseHandle( stdOutProcHandle );
--  result := WinBase.CloseHandle( stdErrProcHandle );
END Launch;

=========== NTSntServerProcess.ads =============

WITH Win32.WinNT;

PACKAGE NTSntServerProcess IS

  PACKAGE WinNT RENAMES Win32.WinNT;

  -- Creates a separate process such that the standard input, standard
output, and standard
  -- error files are redirected to pipes, and returns the file handles
associated with those
  -- pipes.

  PROCEDURE CreateSubprocessNTS( commandDirNTS  : in String;
                                 commandLineNTS : in String;
                                 workDirNTS     : in String;
                                 windowNameNTS  : in String;
                                 stdInNTS       : out WinNT.HANDLE;
                                 stdOutNTS      : out WinNT.HANDLE;
                                 stdErrNTS      : out WinNT.HANDLE );

  PROCEDURE CloseFilesNTS( stdInNTS  : in WinNT.HANDLE;
                           stdOutNTS : in WinNT.HANDLE;
                           stdErrNTS : in WinNT.HANDLE );

END NTSntServerProcess;

=========== NTSntServerProcess ==============

WITH Win32;
WITH Win32.WinBase;
WITH Win32.WinNT;
WITH System;
WITH Ada.Characters.Latin_1;
WITH Interfaces.C;
 USE Interfaces.C;
WITH Interfaces.C.Strings;
 USE Interfaces.C.Strings;
WITH Win32.WinNT;

PACKAGE BODY NTSntServerProcess IS

  PACKAGE WinBase RENAMES Win32.WinBase;
  USE TYPE Win32.BOOL;

  -- Creates a separate process such that the standard input, standard
output, and standard
  -- error files are redirected to pipes, and returns the file handles
associated with those
  -- pipes.

  PROCEDURE CreateSubprocessNTS( commandDirNTS  : in String;
                                 commandLineNTS : in String;
                                 workDirNTS     : in String;
                                 windowNameNTS  : in String;
                                 stdInNTS       : out WinNT.HANDLE;
                                 stdOutNTS      : out WinNT.HANDLE;
                                 stdErrNTS      : out WinNT.HANDLE ) IS
   result : Win32.BOOL;
    commandDir       : CHAR_ARRAY := To_C( commandDirNTS );
   commandLine      : CHAR_ARRAY := To_C( commandLineNTS );
   currentDir       : CHAR_ARRAY := To_C( workDirNTS );
   windowName       : CHAR_ARRAY := To_C( windowNameNTS );
   startupInfo      : ALIASED WinBase.STARTUPINFOA;
   processInfo      : ALIASED WinBase.PROCESS_INFORMATION;
   stdInLocHandle   : ALIASED WinNT.HANDLE;
   stdOutLocHandle  : ALIASED WinNT.HANDLE;
   stdErrLocHandle  : ALIASED WinNT.HANDLE;
   tmpInLocHandle   : ALIASED WinNT.HANDLE;
   tmpOutLocHandle  : ALIASED WinNT.HANDLE;
   tmpErrLocHandle  : ALIASED WinNT.HANDLE;
   stdInProcHandle  : ALIASED WinNT.HANDLE;
   stdOutProcHandle : ALIASED WinNT.HANDLE;
   stdErrProcHandle : ALIASED WinNT.HANDLE;
   securityAttrib   : ALIASED WinBase.SECURITY_ATTRIBUTES;

  BEGIN
   securityAttrib.nLength := WinBase.SECURITY_ATTRIBUTES'SIZE/8;
   securityAttrib.bInheritHandle := Win32.TRUE;
   securityAttrib.lpSecurityDescriptor := NULL;

   result := WinBase.CreatePipe( stdInProcHandle'UNCHECKED_ACCESS,
                                 tmpInLocHandle'UNCHECKED_ACCESS,
                                 securityAttrib'UNCHECKED_ACCESS,
                                 0 );

   result := WinBase.DuplicateHandle( WinBase.GetCurrentProcess,
                                      tmpInLocHandle,
                                      WinBase.GetCurrentProcess,
                                      stdInLocHandle'UNCHECKED_ACCESS,
                                      0,
                                      Win32.FALSE,
                                      WinNT.DUPLICATE_SAME_ACCESS );

   result := WinBase.CloseHandle( tmpInLocHandle );

   result := WinBase.CreatePipe( tmpOutLocHandle'UNCHECKED_ACCESS,
                                 stdOutProcHandle'UNCHECKED_ACCESS,
                                 securityAttrib'UNCHECKED_ACCESS,
                                 0 );

   result := WinBase.DuplicateHandle( WinBase.GetCurrentProcess,
                                      tmpOutLocHandle,
                                      WinBase.GetCurrentProcess,
                                      stdOutLocHandle'UNCHECKED_ACCESS,
                                      0,
                                      Win32.FALSE,
                                      WinNT.DUPLICATE_SAME_ACCESS );

   result := WinBase.CloseHandle( tmpOutLocHandle );

   result := WinBase.CreatePipe( tmpErrLocHandle'UNCHECKED_ACCESS,
                                 stdErrProcHandle'UNCHECKED_ACCESS,
                                 securityAttrib'UNCHECKED_ACCESS,
                                 0 );

   result := WinBase.DuplicateHandle( WinBase.GetCurrentProcess,
                                      tmpErrLocHandle,
                                      WinBase.GetCurrentProcess,
                                      stdErrLocHandle'UNCHECKED_ACCESS,
                                      0,
                                      Win32.FALSE,
                                      WinNT.DUPLICATE_SAME_ACCESS );

   result := WinBase.CloseHandle( tmpErrLocHandle );

   startupInfo.cb              :=
Win32.DWORD( WinBase.STARTUPINFOA'SIZE/8 );
   startupInfo.lpReserved      := NULL; --
   startupInfo.lpDesktop       := NULL;
   startupInfo.lpTitle         :=
windowName(windowName'FIRST)'UNCHECKED_ACCESS;
   startupInfo.dwX             := 0;
   startupInfo.dwY             := 0;
   startupInfo.dwXSize         := 0;
   startupInfo.dwYSize         := 0;
   startupInfo.dwXCountChars   := 0;
   startupInfo.dwYCountChars   := 0;
   startupInfo.dwFillAttribute := 0;
   startupInfo.dwFlags         := WinBase.STARTF_USESTDHANDLES;
   startupInfo.wShowWindow     := 0;
   startupInfo.cbReserved2     := 0;
   startupInfo.lpReserved2     := NULL;
   startupInfo.hStdInput       := stdInProcHandle;
   startupInfo.hStdOutput      := stdOutProcHandle;
   startupInfo.hStdError       := stdErrProcHandle;

   result := WinBase.CreateProcess(
               NULL,                                -- LPCTSTR pointer to
name of executable module
               commandLine(commandLine'FIRST)'UNCHECKED_ACCESS, -- LPTSTR
pointer to command line string
               NULL,                                 --
LPSECURITY_ATTRIBUTES pointer to process security attributes
          NULL,                                 -- LPSECURITY_ATTRIBUTES
pointer to thread security attributes
          Win32.TRUE,                           -- BOOL handle inheritance
flag
          WinBase.DETACHED_PROCESS,             -- DWORD creation flags
          NULL,                                 -- LPVOID pointer to new
environment block
          currentDir(currentDir'FIRST)'UNCHECKED_ACCESS, -- LPCTSTR pointer
to current directory name
          startupInfo'UNCHECKED_ACCESS,         -- LPSTARTUPINFO pointer to
STARTUPINFO
          processInfo'UNCHECKED_ACCESS          -- LPPROCESS_INFORMATION
pointer to PROCESS_INFORMATION
         );

   result := WinBase.CloseHandle( stdInProcHandle );
   result := WinBase.CloseHandle( stdOutProcHandle );
   result := WinBase.CloseHandle( stdErrProcHandle );

   stdInNTS  := stdInLocHandle;
   stdOutNTS := stdOutLocHandle;
   stdErrNTS := stdErrLocHandle;
  END CreateSubprocessNTS;

  PROCEDURE CloseFilesNTS( stdInNTS  : in WinNT.HANDLE;
                           stdOutNTS : in WinNT.HANDLE;
                           stdErrNTS : in WinNT.HANDLE ) IS
   result : Win32.BOOL;
  BEGIN
--   result := WinBase.CloseHandle( stdInProcHandle );
--   result := WinBase.CloseHandle( stdOutProcHandle );
--   result := WinBase.CloseHandle( stdErrProcHandle );
   result := WinBase.CloseHandle( stdInNTS );
   result := WinBase.CloseHandle( stdOutNTS );
   result := WinBase.CloseHandle( stdErrNTS );
  END CloseFilesNTS;

END NTSntServerProcess;







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

end of thread, other threads:[~2000-02-17  0:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-02-15  0:00 not really an Ada question Ehud Lamm
2000-02-16  0:00 ` Robert Dewar
2000-02-16  0:00   ` Ehud Lamm
2000-02-16  0:00     ` Ehud Lamm
2000-02-17  0:00       ` Charles Hixson
2000-02-17  0:00       ` Robert A Duff
2000-02-17  0:00 ` not really an Ada question (long answer) DuckE

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