Comandos.pas 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. {Unidad que implementa la ejecución de comandos de tipo: %EDIT, %EXPLORER, ...}
  2. unit Comandos;
  3. {$mode objfpc}{$H+}
  4. interface
  5. uses
  6. Classes, SysUtils, MisUtils, FrameTabSession, Globales, FrameTabSessions,
  7. process, Parser;
  8. const INI_COMM = '%'; //Initial character for commands
  9. function ExecSFTP(usr, pwd, ip, cmds: string): boolean;
  10. function ProcessCommand(lin: string; ses: TfraTabSession; tabSessions: TfraTabSessions): boolean;
  11. implementation
  12. function ExecSFTP(usr, pwd, ip, cmds: string): boolean;
  13. //Ejecuta el cliente SFTP. Devuelve FALSE si hubo error
  14. var
  15. p : TProcess; //el proceso a manejar
  16. begin
  17. Result := true;
  18. StringToFile(cmds, 'killme.tmp'); //Ceea archivo en blanco.
  19. p := TProcess.Create(nil); //Crea proceso
  20. p.Options:= p.Options + [poNoConsole, poWaitOnExit];
  21. p.Executable:='psftp.exe';
  22. p.Parameters.Clear;
  23. p.Parameters.Add(usr+ '@' + ip);
  24. p.Parameters.Add('-pw');
  25. p.Parameters.Add(pwd);
  26. p.Parameters.Add('-b');
  27. p.Parameters.Add('killme.tmp');
  28. try
  29. p.Execute;
  30. except
  31. Result := false;
  32. MsgBox('Fallo al iniciar aplicativo: '+ p.Executable);;
  33. end;
  34. p.Free;
  35. DeleteFile('killme.tmp'); //Limpia la casa
  36. end;
  37. function ProcessCommand(lin: string; ses: TfraTabSession; tabSessions: TfraTabSessions): boolean;
  38. {Procesa una línea que debe contener un comando. Si no encuentra un comando, devuelve
  39. FALSE.}
  40. var
  41. linCommand: TStringList;
  42. begin
  43. if copy(lin, 1, 1) = INI_COMM then begin //Es un comando.
  44. //Comando equivalente al lenguaje de macros
  45. linCommand := TStringList.Create;
  46. linCommand.Text := copy(lin, 2, length(lin));
  47. cxp.Compilar('current file', linCommand);
  48. if cxp.HayError then begin
  49. cxp.ShowError;
  50. end;
  51. linCommand.Destroy;
  52. exit(true);
  53. end else begin //No se reconoce como comando.
  54. exit(false);
  55. end;
  56. end;
  57. end.