Win32.WinApplications.Mod 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. MODULE WinApplications; (* ll, fof : call windows applications from within WinAos *)
  2. (*ll, add statements for waiting process terminate in procedure Callprocess, 23.11.2007*)
  3. (*ll, add return result of CallProcess Procedure. IF resturn result = 0 THEN execution success END, 28.11.2007*)
  4. IMPORT Kernel32, KernelLog, Commands, Strings, SYSTEM, Options;
  5. PROCEDURE CallProcess( par: ARRAY OF CHAR; visible: BOOLEAN ): LONGINT;
  6. VAR bool: LONGINT; start: Kernel32.StartupInfo; pi: Kernel32.ProcessInformation; result: LONGINT;
  7. BEGIN
  8. result := -1;
  9. start.cb := SIZEOF( Kernel32.StartupInfo );
  10. start.dwFlags := {Kernel32.StartFUseShowWindow};
  11. IF visible THEN start.wShowWindow := 1; ELSE start.wShowWindow := 0; END;
  12. KernelLog.String( "Calling Windows Application: " ); KernelLog.String( par ); KernelLog.Ln;
  13. bool := Kernel32.CreateProcess( NIL , par, NIL , NIL , Kernel32.False, 0, NIL , NIL , start, pi );
  14. result := Kernel32.WaitForSingleObject(pi.hProcess, Kernel32.Infinite);
  15. bool := Kernel32. GetExitCodeProcess(pi.hProcess, result);
  16. RETURN result
  17. END CallProcess;
  18. PROCEDURE Call*( CONST proc, par: ARRAY OF CHAR): LONGINT;
  19. VAR call: ARRAY 1024 OF CHAR;
  20. BEGIN
  21. call := '"'; Strings.Append (call, proc); Strings.Append (call, '" '); Strings.Append (call, par);
  22. RETURN CallProcess (call, TRUE);
  23. END Call;
  24. PROCEDURE Run*(context : Commands.Context);
  25. VAR options: Options.Options; visible: BOOLEAN; cmdpar: ARRAY 256 OF CHAR; res: LONGINT;
  26. BEGIN
  27. NEW (options);
  28. options.Add("h", "hide", Options.Flag);
  29. IF options.Parse(context.arg,context.error) THEN
  30. visible := ~options.GetFlag ("h");
  31. ELSE
  32. visible := TRUE;
  33. END;
  34. context.arg.Ln (cmdpar);
  35. res := CallProcess (cmdpar, visible);
  36. IF res = 0 THEN KernelLog.String( "should have worked fine .... " ); KernelLog.Ln;
  37. ELSE KernelLog.String( "ERROR: " ); res:= Kernel32.GetLastError(); KernelLog.Int(res, 1 ); KernelLog.Ln;
  38. END;
  39. context.result := res;
  40. END Run;
  41. END WinApplications.
  42. SystemTools.Free WinApplications ~
  43. System.Free WinApplications ~
  44. ~
  45. WinApplications.Run avrdude -help ~
  46. Aos.Call WinApplications.Run avrdude -p m128 -c avrisp -P com1 -e ~
  47. Aos.Call WinApplications.Run Notepad Test.bat ~
  48. Aos.Call WinApplications.Run Test.bat ~
  49. ~
  50. EditTools.OpenAscii Test.Bat ~