Skip to main content

I am trying to set a windows variable in COBOL that I will be able to read in a C# program I am calling from COBOL.

"SET testvar=xx" works at a DOS prompt.

However the following does not work.

move "SET testvar=xx" to AFLD60
CALL "C$SYSTEM" USING AFLD60, 97 END-CALL. | Called ASYNCH so no delay

Any ideas would be most appreciated.

Thanks,

Steve

 

I am trying to set a windows variable in COBOL that I will be able to read in a C# program I am calling from COBOL.

"SET testvar=xx" works at a DOS prompt.

However the following does not work.

move "SET testvar=xx" to AFLD60
CALL "C$SYSTEM" USING AFLD60, 97 END-CALL. | Called ASYNCH so no delay

Any ideas would be most appreciated.

Thanks,

Steve

 

C$SYSTEM will execute a new command prompt to run the SET command.  That will set the environment variable there and that environment will go away when the command prompt exits.  To set an environment variable in the same environment as your COBOL run unit, use the Format 6 SET statement:  SET ENVIRONMENT.


I am trying to set a windows variable in COBOL that I will be able to read in a C# program I am calling from COBOL.

"SET testvar=xx" works at a DOS prompt.

However the following does not work.

move "SET testvar=xx" to AFLD60
CALL "C$SYSTEM" USING AFLD60, 97 END-CALL. | Called ASYNCH so no delay

Any ideas would be most appreciated.

Thanks,

Steve

 

Agreeing with BSinclair    SET ENVIRONMENT e TO ws-vbl  

and the environmental variables are available to any subprogram called.  Wouldn't leave home without it.

In the subprograms, ACCEPT ws-var FROM ENVIRONMENT e  


I am trying to set a windows variable in COBOL that I will be able to read in a C# program I am calling from COBOL.

"SET testvar=xx" works at a DOS prompt.

However the following does not work.

move "SET testvar=xx" to AFLD60
CALL "C$SYSTEM" USING AFLD60, 97 END-CALL. | Called ASYNCH so no delay

Any ideas would be most appreciated.

Thanks,

Steve

 

Yes, we use SET ENVIRONMENT quite extensively, however since I have to call my C# .exe with C$SYSTEM it wont help. I will flag your response as the answer, because I have found a simpler work around that does not involve environment variables.

Thanks,

Steve


Yes, we use SET ENVIRONMENT quite extensively, however since I have to call my C# .exe with C$SYSTEM it wont help. I will flag your response as the answer, because I have found a simpler work around that does not involve environment variables.

Thanks,

Steve

I went looking for info on exposing internal values to the shell environment when calling C$SYSTEM and found this forum/thread.  I figured I would add some extra information/findings:

  • The SET ENVIRONMENT "varname" TO "varvalue" only affects the cobol environment.  A call using C$SYSTEM will not have the "varname" in the shell environment (true for unix/linux and windows)
  • You can create a wrapper batch file or script before starting your cobol program, then put the "varvalue"s onto the command line.  Inside the batch file/script you can set the environment variables you need from the command line parameters. 
    • For windows command: eg) use C$SYSTEM to call "MYWRAPPER MYVALUE1 MYVALUE2", and inside MYWRAPPER.BAT
      • SET MYVAR1=%1%
      • SET MYVAR2=%2%
      • SHIFT
      • SHIFT
      • MYOLDCOMMAND
    • For unix/linux, call C$SYSTEM with a wrapper:  mywrapper MYVALUE1 MYVALUE2, and inside mywrapper script:
      • export myvar1="$1"
      • export myvar2="$2"
      • myoldcommand ...
  • Or, finally, your cobol program could write out a proxy batch-file/script-file before calling the proxy command via C$SYSTEM.  Inside the file you set the variables to the values directly, rather than using command line arguments.  eg)
    • export myvar1="MYVALUE1"
    • export myvar2="MYVALUE2"
    • mytargetcommand


------------------------------
Robert Redekop
Senior Programmer/Analyst
Samco Software Inc
Surrey CA
------------------------------