0

I am trying to add a task to compile a program but am having difficulty with setting environment variables. I have this:

{
  // See https://go.microsoft.com/fwlink LinkId=733558
  // for the documentation about the tasks.json format
  "version": "2.0.0",
   "label": "GnuCOBOL - Compile (single file)",
   "type": "shell",
   "options": {
    "env": {
        "PATH=c:\\gnucobol3\\bin"
        "COB_CONFIG_DIR=c:\\gnucobol3\\config"
        "COB_COPY_DIR=c:\\gnucobol3\\copy"
        "COB_INCLUDE_PATH=c:\\gnucobol3\\include"
        "COB_LIB_PATH=c:\\gnucobol3\\lib"
       },
    "command": "cobc",
    "args": [
      "-x",
      "-std=mf",
      "-tPROG.LST",
      "BBCB.CBL"
      ]
    },
} 

The env entries all have squiggly lines underneath and show errors "Colon expected".

I'd appreciate some help. Thanks.

paoloricardo
  • 1,353
  • 2
  • 11
  • 10
  • Please recheck the answers, upvote any "helpful" answers and accept whatever worked for you. If your original question is not answered leave comments on the answers. Thx. – Simon Sobisch Jul 02 '19 at 11:12
  • Please recheck the answers, upvote any "helpful" answers and accept whatever worked for you. If your original question is not answered leave comments on the answers. Thank you. – Simon Sobisch Jul 12 '23 at 06:12

2 Answers2

1

The file paths are for a Windows-based OS (c:\ ...). If you're using Linux, these are incorrect.

This format is JSON.

"env": { ... } takes key:value pairs (determined by the braces) so you will want:

"PATH": "c:\\gnucobol3\\bin",

A colon (:) separates the key and the value and a comma (,) separates key:value pairs.

Unsure whether you need to escape the file paths \\ or just \.

NB "args": [ ... ] takes an array of string values (determined by the square brackets) which is why it differs from "env"

DazWilkin
  • 32,823
  • 5
  • 47
  • 88
  • Daz: thanks. I am not familiar with .JSON hence my puny attempts to define a task. I've modified tasks.json as you suggested and there no more squiggly lines :-) – paoloricardo May 20 '19 at 01:21
  • No worries! It was new to all of us at some point. It's a widely-used format so you'll likely encounter it again. Good to "no squiggly lines" but -- as importantly -- does your code now compile? – DazWilkin May 20 '19 at 03:15
  • Daz: yes, but I needed further assistance with respect to the structure of tasks.json. Thanks again. – paoloricardo May 20 '19 at 06:19
0

The env entries all have squiggly lines underneath and show errors "Colon expected".

Because it expects a contained list which should have colons in and uses commas for separation (identical to the options variable) [note: that actually is a json issue, using that tag may be reasonable]. See Schema for tasks.json.

Also your script has some file names hard-wired (which is a vscode specific), you'll likely want to use the supported variables instead.

Untested result:

{
  // See https://go.microsoft.com/fwlink LinkId=733558
  // for the documentation about the tasks.json format
  "version": "2.0.0",
   "label": "GnuCOBOL - Compile (single file)",
   "type": "shell",
   "options": {
    "env": {
        "PATH": "c:\\gnucobol3\\bin",
        "COB_CONFIG_DIR": "c:\\gnucobol3\\config",
        "COB_COPY_DIR": "c:\\gnucobol3\\copy",
        "COB_INCLUDE_PATH": "c:\\gnucobol3\\include",
        "COB_LIB_PATH": "c:\\gnucobol3\\lib",
       },
    "command": "cobc",
    "args": [
      "-x",
      "-std=mf",
      "-t${fileBasenameNoExtension}.LST",
      "${file}"
      ]
    },
} 
Simon Sobisch
  • 6,263
  • 1
  • 18
  • 38
  • Simon: thanks. I was going to try and 'generalise' the task when I had sorted out the errors. See post above. – paoloricardo May 20 '19 at 01:22
  • @paoloricardo ensure you mark an answer as "solution" (=what worked for you) and upvote any answers that were helpful. Note: for "more info" I highly suggest to check the documentation I've linked... – Simon Sobisch May 20 '19 at 10:51