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

梦想的初衷 提交于 2020-01-04 06:23:09

问题


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"?


回答1:


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.




回答2:


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]




回答3:


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



来源:https://stackoverflow.com/questions/35532928/how-to-run-a-c-program-with-reading-command-line-parameters-in-openvms

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!