From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,4b12bc9a1cc5c6c3 X-Google-Attributes: gid103376,public From: "Condic, Marin D." Subject: Re: Spawning a subprocess and communicating with it. Date: 1998/10/07 Message-ID: #1/1 X-Deja-AN: 398757827 Sender: Ada programming language Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU Content-Type: text/plain; charset="iso-8859-1" MIME-Version: 1.0 Newsgroups: comp.lang.ada Date: 1998-10-07T00:00:00+00:00 List-Id: dennison@TELEPATH.COM writes: > >I don't think that was excetly what he was saying. But if it is, he's >incorrect. Since they are meant to interface with C code directly, OS >routines are usually imported into Ada programs *as*if* they were C routines. >The only problem with writing your code in Ada is that you will find their >interfaces annoyingly non-Ada like. I suppose you also have to be aware that >OS routines aren't always task-safe. > Yeah, I sort of figured that was the case. In this particular instance, I don't need to worry too much about task-safe. I just need to make sure that I have two processes with a pipeline between them which will trade off data in a command/response protocol. >Again, if you aren't ever going to run these processes on separate processors >I would highly suggest using Unix IPC (shared memory or message queues) >rather than sockets (TCP/IP). IPC is a lot easier to interface to and use. On >the other hand, TCP/IP looks better on a resume'... > Actually, my problem is *is* separate processors. I've got a tool which normally would run on a workstation and would want to talk to an embedded processor across a 1553 mux. The embedded software just waits for a message, then responds to it. (maybe a little more complicated than all that, but not by a lot.) What I'm building is a way of running pieces of that embedded software on the workstation and having the tool see it in pretty much the same way. BTW: I was trying to do essentially the same sort of thing on a WinNT platform with the Win32ada bindings without much success. In attempting to build the client/server version of the "Hello World" application, I wrote the following code, which no matter how I changed around the parameters, didn't seem to want to fire up a separate process. Everything I've been able to gather about the CreateProcess call indicates that when this program is run in an MS-DOS command prompt window (on WinNT) it should create another window in which will execute the "Server_01" application. But the CreateProcess call keeps failing and I have no clue as to why. Any guesses? MDC with Win32 ; with Win32.Winbase ; with Ada.Text_IO ; with Ada.Unchecked_Conversion ; with Interfaces.C ; with System ; use Interfaces.C ; procedure Client_02 is -- -- Cause a Server process to be started up. -- Success : Win32.Bool ; Wait : Win32.Dword ; Cmd : aliased constant Char_Array := To_C ("C:\Ada95\Server_01.exe") ; Proc_Security : aliased Win32.Winbase.SECURITY_ATTRIBUTES ; Thread_Security : aliased Win32.Winbase.SECURITY_ATTRIBUTES ; Startup_Info : aliased Win32.Winbase.STARTUPINFOA ; Process_Info : aliased Win32.Winbase.PROCESS_INFORMATION ; -- function CP (A : Interfaces.C.Char_Array) return Win32.LPSTR is function UC1 is new Ada.Unchecked_Conversion ( Source => System.Address, Target => Win32.LPSTR); begin return UC1 (A (A'First)'Address); end CP; -- use Win32 ; use Ada.Text_IO ; use Win32.Winbase ; begin Put_Line ("Client_02: Getting Client Process Info") ; GetStartupInfo ( lpStartupInfo => Startup_Info'Unchecked_Access) ; -- -- Create the subprocess. -- Put_Line ("Client_02: Creating Process") ; Success := CreateProcess ( lpApplicationName => null, lpCommandLine => CP (Cmd), lpProcessAttributes => Proc_Security'Unchecked_Access, lpThreadAttributes => Thread_Security'Unchecked_Access, bInheritHandles => Win32.False, dwCreationFlags => Win32.Winbase.CREATE_NEW_CONSOLE or Win32.Winbase.NORMAL_PRIORITY_CLASS, lpEnvironment => System.Null_Address, lpCurrentDirectory => null, lpStartupInfo => Startup_Info'Unchecked_Access, lpProcessInformation => Process_Info'Unchecked_Access) ; -- if (Success = Win32.False) then Put_Line ("Client_02: Process did not start successfully." & Win32.Bool'Image (Success)) ; else -- Put_Line ("Client_01: Hello World! ") ; delay 1.0 ; -- -- Wait for the other process to complete. -- Wait := WaitForSingleObject ( hHandle => Process_Info.hProcess, dwMilliseconds => INFINITE) ; -- Put_Line ("Client_02: Completed") ; end if ; -- end Client_02 ; Marin D. Condic Real Time & Embedded Systems Pratt & Whitney, Government Engines & Space Propulsion M/S 731-95, P.O.B. 109600, West Palm Beach, FL, 33410-9600 Ph: 561.796.8997 Fx: 561.796.4669 "The speed with which people can change a courtesy into an entitlement is awe-inspiring." -- Miss Manners, February 8, 1994