Advertisement
Najeebsk

CMD3.ahk

Dec 25th, 2021
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; <COMPILER: v1.1.32.00>
  2. #SingleInstance Force
  3. SetworkingDir, %A_workingdir%
  4. ;-------- saved at Najeeb 2021-12-12  17:36 UTC --------------
  5. cmd=
  6. (
  7. HELP /?
  8. TYPE DATA\ALL.ls
  9. TYPE DATA\ATTRIB.ls
  10. TYPE DATA\CMD.ls
  11. TYPE DATA\COPY.ls
  12. TYPE DATA\DEL.ls
  13. TYPE DATA\DIR.ls
  14. TYPE DATA\FIND.ls
  15. TYPE DATA\HELP.ls
  16. TYPE DATA\MD.ls
  17. TYPE DATA\NET.ls
  18. TYPE DATA\NIR.ls
  19. TYPE DATA\REN.ls
  20. TYPE DATA\START.ls
  21. )
  22. cmdx:=""                            ;- first command for test
  23. ;cmdx:="ping autohotkey.com -n 4"
  24. #warn
  25. #noenv
  26. name1:="NAJEEB CMD"
  27. global name1
  28. e:=""
  29. CPX:="cp" . DllCall("GetOEMCP", "UInt")        ;- get CODEPAGE e.g. CP850
  30. ;setworkingdir,%a_scriptdir%
  31. Gui,1:default
  32. Gui,1: -DPIScale
  33. Gui,1:Color,Black,Black                        ; GUI black   / EDIT is BLACK
  34. wa:=A_screenwidth,ha:=A_screenHeight,xx:=100
  35. ;- maybe change fontsize
  36. ;============ GUISIZEx DPIx 4Kx 3840*2160 is 100% ============
  37. if (wa=3840)
  38.  Gui,1:Font,s16 cYellow,Lucida Console
  39. ;============ GUISIZEx DPIx FHD 1920*1080 is 100% ============
  40. else if (wa=1920)
  41.  Gui,1:Font,s12 cYellow,Lucida Console
  42. else
  43.  Gui,1:Font,s12 cYellow,Lucida Console
  44. ;=============================================================
  45. x:=(wa*1)/xx,y:=(ha*1)/xx,w:=(wa*70)/xx,h:=(ha*60)/xx
  46. Gui, Add, Edit, x%x%   y%y%  w%w% h%h% vED1,%cmd%               ;- here the output
  47. x:=(wa*1)/xx,y:=(ha*63)/xx,w:=(wa*65)/xx,h:=(ha*6)/xx
  48. Gui, Add, Edit, x%x%   y%y% w%w%  h%h% vED2,%cmdx%           ;- added CMDx command above for test / write command here and then ENTER
  49. x:=(wa*67)/xx,y:=(ha*63)/xx,w:=(wa*6)/xx,h:=(ha*3.2)/xx
  50. Gui, add, Edit, x%x%  y%y% w%w%  h%h% vED3,                          ;- write ENDED when command finished
  51. x:=(wa*67)/xx,y:=(ha*67)/xx,w:=(wa*6)/xx,h:=(ha*3.2)/xx
  52. Gui,add,button, x%x%  y%y% w%w%  h%h% gPrintx, PRINT          ;- write to file last commands and outputs
  53. x:=(wa*2)/xx,y:=(ha*2)/xx,w:=(wa*75)/xx,h:=(ha*75)/xx
  54. Gui, Show,x%x% y%y% w%w% h%h%,%name1%
  55. gosub,a0
  56. GuiControl,1: Focus,ED2
  57. ;send,^{end}
  58. return
  59. ;-------------------------
  60. Guiclose:
  61. Exitapp
  62. esc::exitapp
  63. ;-------------------------
  64. ~$enter::
  65. gosub,a0
  66. return
  67. ;=========================================================
  68. AddOutputInGui(output) {
  69.    Control, EditPaste, %output%`r`n, Edit1,%name1%    ;- display output in 1st EDIT
  70. }
  71. ;=========================================================
  72.  
  73. A0:
  74. Gui,1:submit,nohide
  75. ed2a:="cmd /c " . ed2
  76. ;CmdRet(ED2a, Func("AddOutputInGui"),CPX)
  77. xxc:=cmdret(ED2a, Func("AddOutputInGui"),CPX)
  78. e .="`r`n===============================`r`n" . ed2 . " =`r`n-------------------------------`r`n" . xxc . "`r`n===============================`r`n"
  79. e := RegExReplace(e, "((^)|\R)\h*(?=\R|$)(?(2)\R)")              ;- remove empty lines
  80. gosub,clear
  81. return
  82. ;-------------------------
  83. CLEAR:
  84. Gui,1:submit,nohide
  85. Guicontrol,1:,ED2,
  86. Guicontrol,1:,ED3,ENDED
  87. GuiControl,1: Focus,ED2
  88. return
  89. ;-------------------------
  90. printx:
  91. f1=%a_desktop%\%a_now%_DOS_SCREEN_OUTPUT.txt
  92. Gui,1:submit,nohide
  93. if e<>
  94.  {
  95.  fileappend,%e%,%f1%,utf-8
  96.  run,%f1%
  97.  e:=""
  98.  }
  99. return
  100.  
  101. ;=========================================================
  102. CmdRet(sCmd, callBackFuncObj := "", encoding := "CP0")
  103. {
  104.    static HANDLE_FLAG_INHERIT := 0x00000001, flags := HANDLE_FLAG_INHERIT
  105.         , STARTF_USESTDHANDLES := 0x100, CREATE_NO_WINDOW := 0x08000000
  106.    hPipeRead:=""
  107.    hPipeWrite:=""
  108.    sOutput:=""
  109.    DllCall("CreatePipe", "PtrP", hPipeRead, "PtrP", hPipeWrite, "Ptr", 0, "UInt", 0)
  110.    DllCall("SetHandleInformation", "Ptr", hPipeWrite, "UInt", flags, "UInt", HANDLE_FLAG_INHERIT)
  111.    
  112.    VarSetCapacity(STARTUPINFO , siSize :=    A_PtrSize*4 + 4*8 + A_PtrSize*5, 0)
  113.    NumPut(siSize              , STARTUPINFO)
  114.    NumPut(STARTF_USESTDHANDLES, STARTUPINFO, A_PtrSize*4 + 4*7)
  115.    NumPut(hPipeWrite          , STARTUPINFO, A_PtrSize*4 + 4*8 + A_PtrSize*3)
  116.    NumPut(hPipeWrite          , STARTUPINFO, A_PtrSize*4 + 4*8 + A_PtrSize*4)
  117.    
  118.    VarSetCapacity(PROCESS_INFORMATION, A_PtrSize*2 + 4*2, 0)
  119.    if !DllCall("CreateProcess", "Ptr", 0, "Str", sCmd, "Ptr", 0, "Ptr", 0, "UInt", true, "UInt", CREATE_NO_WINDOW
  120.                               , "Ptr", 0, "Ptr", 0, "Ptr", &STARTUPINFO, "Ptr", &PROCESS_INFORMATION)
  121.    {
  122.       DllCall("CloseHandle", "Ptr", hPipeRead)
  123.       DllCall("CloseHandle", "Ptr", hPipeWrite)
  124.       throw Exception("CreateProcess is failed")
  125.    }
  126.    DllCall("CloseHandle", "Ptr", hPipeWrite)
  127.    VarSetCapacity(sTemp, 4096), nSize := 0
  128.    while DllCall("ReadFile", "Ptr", hPipeRead, "Ptr", &sTemp, "UInt", 4096, "UIntP", nSize, "UInt", 0) {
  129.       sOutput .= stdOut := StrGet(&sTemp, nSize, encoding)
  130.       ;sOutput .= stdOut := StrGet(&sTemp, nSize)
  131.       ;sOutput .= stdOut := StrGet(&sTemp, nSize, CPX)
  132.       ( callBackFuncObj && callBackFuncObj.Call(stdOut) )
  133.    }
  134.    DllCall("CloseHandle", "Ptr", NumGet(PROCESS_INFORMATION))
  135.    DllCall("CloseHandle", "Ptr", NumGet(PROCESS_INFORMATION, A_PtrSize))
  136.    DllCall("CloseHandle", "Ptr", hPipeRead)
  137.    Return sOutput
  138. }
  139. ;--------------------- END SCRIPT---------------------------------
  140. #R::Reload
  141. #S::Suspend
  142. #P::Pause
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement