how to run a c program with reading command line parameters in openvms?

1.2k views Asked by At

I built a simple program try to print the command line parameters.

The code is below and I built an executable file (TEST.EXE).

int main(int argc, char *argv[])
{
    int i;
    printf("%s\n",argv[0]);
    for (i = 1;  i < argc;  i++)
       printf("argument %d: %s\n", i, argv[i]);
    exit (EXIT_SUCCESS);
}

I try to run the TEST.EXE and print the parameters but fail.

The result of command RUN TEST.EXE test1 test2:

%DCL-W-MAXPARM, too many parameters - reenter command with fewer parameters

What can I do to print "test1" and "test2"?

3

There are 3 answers

0
user2116290 On BEST ANSWER

In addition, if you need to preserve the case of the arguments, you have to quote these arguments or enter

$ SET PROCESS/PARSE_STYLE=EXTENDED

once in the lifetime of your process and

$ DEFINE/USER DECC$ARGV_PARSE_STYLE TRUE

before running your program with a specific foreign command or by using automatic foreign commands (DCL$PATH). Otherwise all the unquoted arguments are converted to lowercase characters.

PS: VMS has a command language, that is, you have to enter a command to run a program. By default, file names are no commands. With defining DCL$PATH you change this default behaviour.

0
Hein On

Defining a foreign command as per 'a3f' is the 'proper' way to do it albeit somewhat tedious and 2-stepped.

You may also want to try the MCR 'trick'. MCR being short for the Monitor Command Routine from the 40+ year old PDPD-11 Operating System RSX.

Now MCR defaults to look for program in SYS$SYSTEM, so you do have to specify the current location:

$ MCR dev:[dir]TEST this is a test.

There is also a 1-1/2 step approach using DCL$PATH. This works mostly like the Unix and Windows path, providing places to look for DCL scripts or programs if an unknown command is entered.

For example

$ DEFINE DCL$PATH SYS$DISK:[],SYS$LOGIN:,SYS$SYSTEM:

Now just type : TEST this.

Hein

0
a3f On

The RUN command doesn't support any command line arguments. Define a foreign command and use that instead. From David Mathog's beginner FAQ:

How do I start a program?

  • Method 2: Use the RUN command:

    $ run program_nameNo command line arguments allowed

  • Method 3: Define a foreign command for it, then run it. In the following example where is a logical name equivalent to the location of the program.

    $ new_command :== $where:program_name $ new_command [command line arguments]