Announcement

Collapse
No announcement yet.

Is there a way to get the IDE to call a batch file or exe after each compile?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Is there a way to get the IDE to call a batch file or exe after each compile?

    Is there a way to get the IDE to call a batch file or exe after each compile?

    Am I correct in my assumption that the IDE calls the compiler.exe? Or is the compiler IDE too?

  • #2
    The IDE is named pbedit.exe (or ccedit.exe) and the compiler is named PBWin.exe (or PBCC.EXE). The IDE calls PBWin.exe with compiler directives in a command$, so it should be possible to do a little trick by creating a tiny shell program that sort of replaces and then calls the compiler and finally does what you ask for.

    To try: save the following as PBWin.bas somewhere (not the \bin sub folder) and compile. Then rename PBWin.exe in the \bin folder to PBWinB.EXE and move the new little PBWin.exe to the bin folder. The IDE will call PBWin.EXE, which now is the tiny "shell" program you have made and it in turn calls the renamed, "real" compiler with the command$ from the IDE.

    Code just an example - second SHELL should of course be whatever you want to do after compile. One problem is that if compile fails, the second SHELL command will still be performed. Also remember to move or copy the "shell" program to the \bin folder after each new change and re-compile of the code below.
    Code:
    #COMPILE EXE
    
    FUNCTION PBMAIN () AS LONG
      SHELL("PBWinB.EXE " + COMMAND$)  ' call the renamed "real" compiler
      SHELL("cmd.exe /?")  ' whatever...
    END FUNCTION

    Comment


    • #3
      Börje is right.
      To add a little, on exit the compiler set an ErrorLevel aka ExitCode to signal error status.
      It might be a good thing to catch and re-transmit this info to the IDE,
      it could also be used to know if an error occured.

      Click image for larger version  Name:	PbWinFake.png Views:	1 Size:	15.9 KB ID:	777498

      Code:
      'How to execute a program after each time the IDE call the compiler...
      'First, copy PbWin.exe in PBWinRZ.exe
      'Then put this exe in the Bin folder and name it PbWin.exe
      'ErrorLevel/ExitCode zero mean no error.
      
      'Window:  IDE is PbEdit.exe and compiler is PbWin.exe.
      'For Console: IDE is CcEdit.exe and compiler is PbCc.exe, you may use PbCcRz.exe instead of PBWinRZ.exe.
      
      #COMPILE EXE '#Win 9.07#
      #REGISTER NONE
      #DIM ALL
      #INCLUDE "Win32Api.inc"
      
      FUNCTION PBMAIN
       LOCAL ProcessInfo AS PROCESS_INFORMATION
       LOCAL StartInfo   AS STARTUPINFO
       LOCAL sCmdLine    AS STRING
       LOCAL sParam      AS STRING
       LOCAL hProcess    AS DWORD
       LOCAL ExitCode    AS LONG
      
       sParam = COMMAND$ 'Get the IDE command line
      
       IF LEFT$(sParam, 10) = "ErrorLevel" THEN 'This does not come from the IDE but come from self
         MessageBox(%HWND_DESKTOP, (sParam), "PBWin.Insert", %MB_OK OR %MB_TOPMOST) 'Simply show error code and original $COMMAND
       ELSE
         'Do Call the compiler with the original commad line
         StartInfo.cb          = SIZEOF(STARTUPINFO)
         StartInfo.dwFlags     = %STARTF_USESHOWWINDOW OR %STARTF_USESTDHANDLES
         StartInfo.wShowWindow = %SW_SHOW
      
         sCmdLine = "PBWinRZ.exe" & $SPC & sParam 'PBWinRZ is the original PBWin.exe
         CreateProcess(BYVAL %NULL, BYVAL STRPTR(sCmdLine), BYVAL 0, BYVAL 0, BYVAL 1, _
                       %NORMAL_PRIORITY_CLASS, BYVAL %NULL, BYVAL %NULL, StartInfo, ProcessInfo)
         WaitForSingleObject(ProcessInfo.hProcess, %INFINITE) 'Wait until compilation is done
         '-Here, compilation is done
         GetExitCodeProcess(ProcessInfo.hProcess, ExitCode)   'Get exit code to re-transmit to the IDE
         CloseHandle(ProcessInfo.hProcess)                    'No need no more, so clean up
         FUNCTION = ExitCode                                  'Re-transmit exit code aka ErrorLevel to the IDE
      
         'Calling self for the fun of it, the "ErrorLevel" string in COMMAND$ tell that it's not an IDE call.
         sCmdLine = "PbWin.exe ErrorLevel" & STR$(ExitCode) & $CRLF & "Original COMMAND$ was: " & sParam 'Or : sCmdLine = "NotePad.exe"
         CreateProcess(BYVAL %NULL, BYVAL STRPTR(sCmdLine), BYVAL 0, BYVAL 0, BYVAL 1, _
                       %NORMAL_PRIORITY_CLASS, BYVAL %NULL, BYVAL %NULL, StartInfo, ProcessInfo)
         CloseHandle(ProcessInfo.hProcess) 'No need no more, so clean up
       END IF
      
      END FUNCTION
      '______________________________________________________________________________
      '
      Last edited by Pierre Bellisle; 30 Dec 2018, 11:14 AM.

      Comment


      • #4
        Thank you! Great ideas.

        Comment

        Working...
        X