Menu

how to hide error messages from sub-process

GnuCOBOL
Jason
2022-09-01
2022-09-01
  • Jason

    Jason - 2022-09-01

    In my code I’m doing the following to identify is a file exists (on a Mac)

     IF OS-IDENTIFIED = "MACOS"
                MOVE "ls /usr/local/bin/chromedriver > bot.check"
                 TO SYSTEM-COMMAND
               END-IF.
               ...
               ...
     CALL "SYSTEM" USING SYSTEM-COMMAND.
    

    Then I read the bot.check file to determine if the file chromedriver was found.

    This works fine.

    But when I exit the program (back to the OS) I see the error message resulting from the ls command when the file was not found:

    ls: /usr/local/bin/chromedriver: No such file or directory

    Anyway I can prevent that? It’s not a major issue but I’d prefer to return to an error message free screen when existing the program.

     
  • Simon Sobisch

    Simon Sobisch - 2022-09-01

    Add 2>/dev/null to your command for CALL 'SYSTEM'- and even better :use CALL 'CBL_CHECK_FILE_EXIST' in the first place.

     
  • Jason

    Jason - 2022-09-01

    the what now? I didn't know about CBL_CHECK_FILE_EXIST. Thank you!

     
    • Simon Sobisch

      Simon Sobisch - 2022-09-01

      It is very likely that the Programmer's Guide has it...
      For a list of the system routines available with GnuCOBOL have a look at the manual (shipped PDF and info page) or at cobc --list-system.

       

Log in to post a comment.