Menu

Call SYSTEM with Windows

GnuCOBOL
Jason
2022-07-05
2022-07-15
  • Jason

    Jason - 2022-07-05

    hello, I suspect this is more a Windows question than a GnuCOBOL question so apologies in advance if that's an issue.

    I want to open a file created by my COBOL program in an editor on Windows. I use this code:

    IF INPUT-KEY = "O"
      IF OS-IDENTIFIED = "WIN32"
       CALL "SYSTEM" 
       USING "notepad file1"
      CALL "SYSTEM" 
       USING "notepad file2"
      END-IF 
    END-IF
    

    When this code is invoked "file1" is indeed loaded in Notepad. But in order to see 'file2" I have to close the file1 Notepad, then Notepad containing file2 is displayed.

    I want to open Notepad twice, one containing file1 and one containing file2.

    On the Mac two instances of the Textedit app are executed.

    Any workaround?

    Thank you!

     

    Last edit: Simon Sobisch 2022-07-05
    • Brian Tiffin

      Brian Tiffin - 2022-07-05

      Can't test, @flaneur7508, but seeing as you know you are on WIN32 in that code block, try:

      CALL "SYSTEM" USING "start notepad file1"
      CALL "SYSTEM" USING "start notepad file2"
      

      Not sure if you'll get CMD consoles flashing in the background or not, or all the other edge case issues that may arise.

      If you wanted to go cross platform, you might be able to make a POSIX start script somewhere in your PATH that looks for a notepad argument and replace the whole thing with vim and ending with &. wink wink smiley.

      (If you have WINE installed on a GNU/Linux system, which ships with notepad it usually invokes the entire emulated WINE system, which is expensive if not already running).

      Cheers,
      Blue

       
      👍
      1
      • Jason

        Jason - 2022-07-06

        Thanks Brian, that does the trick! Cheers!

         
  • Simon Sobisch

    Simon Sobisch - 2022-07-05

    The solution is to never hard-wire external programs in your code.

    Instead just call a script - for example CALL "SYSTEM" USING "TEXTEDIT OPEN file1" and then have TEXTEDIT as exutable script in PATH (for Win32 name it ".bat", for other systems add the #!/bin/bash in the first line.

    You can then check in there for the first argument and if it is WAIT execute a "waiting" texteditor, otherwise a background one.

    For Win32 you could do this with cmd /k "start /nowait notepad.exe %2" for other systems normally end with a &.

    If you use multiple programs you could also come up with a EXTCALL script that executes multiple different programs (and for example also get a "print" command, ...)

     
    • Brian Tiffin

      Brian Tiffin - 2022-07-05

      Off topic side comment: I gotta start hitting refresh more often, and stop posting advice that is not as complete as Simon's better answers that go in before I finish typing. :-)

       
      😄
      1
    • Jason

      Jason - 2022-07-06

      Yes, sometimes i'm just too lazy :) I do of course see your point.

       
  • Jack Tearle

    Jack Tearle - 2022-07-13

    I use:
    CALL SYSTEM USING "explore.exe file.ext"
    This way, the program that is opened is the one associated with the file extension.

     
    • Simon Sobisch

      Simon Sobisch - 2022-07-13

      Wouldn't be CALL SYSTEM USING "file.ext" work, too and be more portable at the same time?

       
  • Jack Tearle

    Jack Tearle - 2022-07-15

    Not quite. I was assuming that the file is not an executable, but a data file. So rather than force the program by using call system using "adobereader file.pdf", calling system using "explore.exe file.pdf" will start whatever program that has been assigned to open pdf files.

     
    • Simon Sobisch

      Simon Sobisch - 2022-07-15

      I've thought that executing the "file" would automatically open it without using explorer.exe, but if that's your test result - sure stay with it.

       

Log in to post a comment.