Hide a CMD window in a Visual COBOL native app

[Migrated content. Thread originally posted on 25 October 2011]

Hello,

I want to execute a system command from a native app which I am migrating from RM/COBOL for Windows. This execution in particular looks like this in RM:

CALL "C$GUICFG" USING "System window type=hidden " Z9.
STRING 'CMD /C/S ECHO ' MENSA ' >> \VPC\OUT\ET'
DELIMITED SIZE INTO MANDATO.
CALL "SYSTEM" USING MANDATO.
CALL "C$GUICFG" USING "System window type=show " Z9.


C$GUICFG was used in this case for hidding the new window. Do you know how to obtain the same behaviour in the Visual COBOL version?

Regards
  • Verified Answer

    Something like the following should work:


           identification division.
           program-id. Program1.
           data division.
           working-storage section.
           01 command-line pic x(100).
           01 command-line-len pic x(4) comp-5. 
           01 run-unit-id    pic x(8) comp-5.
           01 stack-size     pic x(4) comp-5. 
           01 flags          pic x(4) comp-5. 
           01 status-code    pic x(4) comp-5.
           01 any-key        pic x.
           01 comspec        pic x(200)  value spaces.
           procedure division.
               
               display "COMSPEC" upon environment-name
               accept comspec from environment-value
               
               string comspec delimited by " "
                  " /C echo ' MENSA '>>testfile.txt"
                     delimited by size
                  into command-line
               end-string
                 
               move length of command-line to command-line-len
               move 1 to flags   

               call "CBL_EXEC_RUN_UNIT"
                  using by reference command-line
                        by value     command-line-len
                        by reference run-unit-id
                        by value     stack-size
                        by value     flags
                  returning    status-code
               end-call

               accept any-key
               stop run.