[fpc-pascal] Interactive SHELL?
Hi All: What I need to do is to shell out to another program [GNUpg] and allow the user to interact with it (enter a pass phrase). I have tried all the FpExec routines, the Shell routines etc. They ALL execute gpg correctly, with the proper command-line args, I see gpg's response on the console screen, and it's request for a pass phrase, but, the user can NOT interact with it as the keyboard is dead. Now, this is understandable, since it is the main program which issued the shell command, and any input would have to come from the entity opening the shell (the parent program, not the console user). Is there a way to re-direct the local console kybd to the new shell, allowing the user to interact with gpg? Or is there another way to do this? Perhaps shelling out is not the proper way to handle this? The program is being compiled for Linux, with FPC 2.0.0 Best Regards Bob -- PGP Encrypted E-Mail Preferred Public Key at: http://www.tamara-b.org/~bob/pubkey.asc . ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] RV: using Crt Functions inside a thread.
Hi, Can anyone check this prj to see it's happening the same than me? Hi, I have a little program working with Crt units without problem. I have change the print way form, I have pushing Crt Commands inen Fifo (GotoXY, ClrScr, ClrEol, Write,...) and I have created a Thread class to pop this commands to execute it. Problem seems to be cursor position in tty which is not working okey perhaps for using threads? Is any funtion to syncronizing tty each time is writing or changing cursor position? version of compiler a compiling output, Free Pascal Compiler version 2.0.0 [2005/05/15] for i386 Copyright (c) 1993-2005 by Florian Klaempfl Target OS: Linux for i386 Compiling test.dpr Linking test_386 25 Lines compiled, 0.4 sec I have attached an example in order to test it, tia! best regards. unit ApilarCrt; interface uses {$IFDEF LINUX} cthreads, crt, {$ENDIF} Classes, SysUtils; procedure EscrituraDirecta(valor: boolean); procedure ApilarWrite(cadena: string); procedure ApilarWriteLn(cadena: string); overload; procedure ApilarWriteLn; overload; procedure ApilarClrScr; procedure ApilarClrEol; procedure ApilarGotoXY(x: byte; y: byte); function LeerTeclado: char; implementation uses {$IFDEF LINUX} // Crt, {$ELSE} Win32Crt, ShareMem, {$ENDIF} SyncObjs, Contnrs, Utilidades; const MAXIMOS_MSGS_APILAR = 1000; type TipoDatosApilarCrt = (APILAR_CRT_WRITE, APILAR_CRT_WRITELN, APILAR_CRT_WRITELN_STR, APILAR_CRT_CLRSCR, APILAR_CRT_CLREOL, APILAR_CRT_GOTOXY); TipoApilarCrt = record tipo: TipoDatosApilarCrt; x: byte; y: byte; cadena: string; end; p_TipoApilarCrt = ^TipoApilarCrt; TApilarCrtFifo = class private ColaApilarCrt: TQueue; FCritSect: TCriticalSection; function intNumApilarCrtMsg: integer; function intPeekApilarCrtMsg(var msg: TipoApilarCrt; borrar: boolean): boolean; public constructor Create; destructor Destroy; override; procedure PushApilarCrtMsg(msg: TipoApilarCrt); function PopApilarCrtMsg(var msg: TipoApilarCrt): boolean; function PeekApilarCrtMsg(var msg: TipoApilarCrt): boolean; published property NumApilarCrtMsg: integer read intNumApilarCrtMsg; end; TThreadApilarCrt = class(TThread) private intCola: TApilarCrtFifo; public constructor Create(cola: TApilarCrtFifo); destructor Destroy; procedure Execute; override; end; var intEscrituraDirecta: boolean; ApilarCrtFifo: TApilarCrtFifo; ThreadCrtFifo: TThreadApilarCrt; // -- // TApilarCrtFifo // -- constructor TApilarCrtFifo.Create; begin inherited; ColaApilarCrt := TQueue.Create; FCritSect := TCriticalSection.Create; end; destructor TApilarCrtFifo.Destroy; var I: Integer; intmsg: p_TipoApilarCrt; begin FCritSect.Enter; (* for I := 0 to ColaCan.count - 1 do begin Dispose(p_can_msg_t(ColaCan[I])); end; *) while (ColaApilarCrt.Count > 0) do begin intmsg := ColaApilarCrt.Pop; end; ColaApilarCrt.Free; FCritSect.Leave; FCritSect.Free; inherited; end; function TApilarCrtFifo.intNumApilarCrtMsg: integer; begin FCritSect.Enter; intNumApilarCrtMsg := ColaApilarCrt.Count; FCritSect.Leave; end; procedure TApilarCrtFifo.PushApilarCrtMsg(msg: TipoApilarCrt); var intmsg: p_TipoApilarCrt; begin FCritSect.Enter; if ColaApilarCrt.Count < MAXIMOS_MSGS_APILAR then begin new(intmsg); intmsg^ := msg; ColaApilarCrt.Push(intmsg); end; FCritSect.Leave; end; function TApilarCrtFifo.intPeekApilarCrtMsg(var msg: TipoApilarCrt; borrar: boolean): boolean; var intmsg: p_TipoApilarCrt; begin intPeekApilarCrtMsg := false; if ColaApilarCrt.Count = 0 then begin exit; end; intmsg := ColaApilarCrt.Peek; if intmsg <> nil then begin msg := intmsg^; if borrar then begin intmsg := ColaApilarCrt.Pop; // eliminar el registro dispose(intmsg); end; intPeekApilarCrtMsg := true; end; end; function TApilarCrtFifo.PeekApilarCrtMsg(var msg: TipoApilarCrt): boolean; var intmsg: p_TipoApilarCrt; begin FCritSect.Enter; PeekApilarCrtMsg := intPeekApilarCrtMsg(msg, false); FCritSect.Leave; end; function TApilarCrtFifo.PopApilarCrtMsg(var msg: TipoApilarCrt): boolean; var intmsg: p_TipoApilarCrt; begin FCritSect.Enter; PopApilarCrtMsg := intPeekApilarCrtMsg(msg, true); FCritSect.Leave; end; // -- // TThreadApilarCrt // -- constructor TThreadApilarCrt.Create(cola: TApilarCrtFifo); begin intCola := cola; inherited create(true); end; destructor TThreadApilarCrt.Destroy; begin inherited Destroy; end; procedure TThreadApilarCrt.execute; var msg: TipoApilarCrt; x1,y1 :
Re: [fpc-pascal] Interactive SHELL?
> What I need to do is to shell out to another program [GNUpg] and allow the > user to > interact with it (enter a pass phrase). > I have tried all the FpExec routines, the Shell routines etc. They ALL > execute gpg > correctly, with the proper command-line args, I see gpg's response on the > console screen, > and it's request for a pass phrase, but, the user can NOT interact with it as > the keyboard > is dead. > > Now, this is understandable, since it is the main program which issued the > shell command, > and any input would have to come from the entity opening the shell (the > parent program, > not the console user). > > Is there a way to re-direct the local console kybd to the new shell, allowing > the user to > interact with gpg? Or is there another way to do this? Perhaps shelling out > is not the > proper way to handle this? > > The program is being compiled for Linux, with FPC 2.0.0 Do you use units or libraries that might put the terminal in raw mode? Ncurses,crt, video? ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Interactive SHELL?
Marco van de Voort wrote: > > Do you use units or libraries that might put the terminal in raw mode? > Ncurses,crt, video? I am using "crt" for the readkey function in one of my procedures. No ncurses, no video. I am also smart-linking, so the only function compiled in from crt SHOULD be readkey. I will look at unit CRT, and see if perhaps there is a termonal mode command I can issue. Thanks. Bob -- PGP Encrypted E-Mail Prefered Public Key at: http://www.tamara-b.org/~bob/pubkey.asc . ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Interactive SHELL?
On 15 feb 2006, at 20:30, Bob Richards wrote: Do you use units or libraries that might put the terminal in raw mode? Ncurses,crt, video? I am using "crt" for the readkey function in one of my procedures. No ncurses, no video. I am also smart-linking, so the only function compiled in from crt SHOULD be readkey. No, because the crt unit contains initialisation code, and initialisation code of a unit is obviously always linked in and executed. This initialisation code puts the terminal in raw mode, because it's required for crt's functionality. The crt unit does not contain an exported procedure to disable it, since that would also break all crt's functionality. Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Interactive SHELL?
> Marco van de Voort wrote: > > > Do you use units or libraries that might put the terminal in raw mode? > > Ncurses,crt, video? > > I am using "crt" for the readkey function in one of my procedures. No > ncurses, no video. I > am also smart-linking, so the only function compiled in from crt SHOULD be > readkey. > > I will look at unit CRT, and see if perhaps there is a termonal mode command > I can issue. Note that merely including crt already causes capturing of all output by the crt unit. Try, - for testing purposes - to remove crt and use more basic input (readln), and see if it makes the problems disappear. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Interactive SHELL?
Jonas Maebe wrote: > > No, because the crt unit contains initialisation code, and > initialisation code of a unit is obviously always linked in and > executed. This initialisation code puts the terminal in raw mode... Thanks Jonas! That was the issue. So, I will just have to write my own readkey routine, and lose crt. Not a big deal. Thanks again Bob -- PGP Encrypted E-Mail Prefered Public Key at: http://www.tamara-b.org/~bob/pubkey.asc . ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Interactive SHELL?
Marco van de Voort wrote: > Try, - for testing purposes - to remove crt and use more basic input > (readln), and see if it makes the problems disappear. Indeed! Problem gone! now to hide the user's typying from the screen. I was using readkey and echowing back a "*" during password input. I will have to do it another way. Bob -- PGP Encrypted E-Mail Prefered Public Key at: http://www.tamara-b.org/~bob/pubkey.asc . ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal