如何 运行 一个 c 程序在 openvms 中读取命令行参数?
how to run a c program with reading command line parameters in openvms?
我构建了一个简单的程序来尝试打印命令行参数。
代码在下面,我构建了一个可执行文件(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);
}
我尝试 运行 TEST.EXE 并打印参数但失败了。
命令的结果RUN TEST.EXE test1 test2
:
%DCL-W-MAXPARM, too many parameters - reenter command with fewer parameters
如何打印 "test1" 和 "test2"?
RUN
命令不支持任何命令行参数。定义一个外部命令并改用它。来自 David Mathog 的 beginner FAQ:
How do I start a program?
Method 2: Use the RUN
command:
$ run program_name
No 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]
按照 'a3f' 定义外部命令是 'proper' 的方法,尽管有点乏味且需要两步。
您可能还想尝试 MCR 'trick'。
MCR 是 40 多年历史的 PDPD-11 操作系统 RSX 中监控命令例程的缩写。
现在 MCR 默认在 SYS$SYSTEM 中查找程序,因此您必须指定当前位置:
$ MCR dev:[dir]TEST this is a test.
还有一个使用 DCL$PATH 的 1-1/2 步方法。
这主要类似于 Unix 和 Windows 路径,如果输入未知命令,则提供查找 DCL 脚本或程序的位置。
例如
$ DEFINE DCL$PATH SYS$DISK:[],SYS$LOGIN:,SYS$SYSTEM:
现在只需输入:TEST this.
海因
此外,如果您需要保留参数的大小写,您必须引用这些参数或输入
$ SET PROCESS/PARSE_STYLE=EXTENDED
在你的进程的生命周期中一次并且
$ DEFINE/USER DECC$ARGV_PARSE_STYLE TRUE
在 运行使用特定的外部命令或使用自动外部命令 (DCL$PATH) 连接您的程序之前。否则所有未加引号的参数都将转换为小写字符。
PS:VMS有命令语言,就是你要给运行一个程序输入命令。默认情况下,文件名不是命令。通过定义 DCL$PATH,您可以更改此默认行为。
我构建了一个简单的程序来尝试打印命令行参数。
代码在下面,我构建了一个可执行文件(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);
}
我尝试 运行 TEST.EXE 并打印参数但失败了。
命令的结果RUN TEST.EXE test1 test2
:
%DCL-W-MAXPARM, too many parameters - reenter command with fewer parameters
如何打印 "test1" 和 "test2"?
RUN
命令不支持任何命令行参数。定义一个外部命令并改用它。来自 David Mathog 的 beginner FAQ:
How do I start a program?
Method 2: Use the
RUN
command:
$ run program_name
No 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]
按照 'a3f' 定义外部命令是 'proper' 的方法,尽管有点乏味且需要两步。
您可能还想尝试 MCR 'trick'。 MCR 是 40 多年历史的 PDPD-11 操作系统 RSX 中监控命令例程的缩写。
现在 MCR 默认在 SYS$SYSTEM 中查找程序,因此您必须指定当前位置:
$ MCR dev:[dir]TEST this is a test.
还有一个使用 DCL$PATH 的 1-1/2 步方法。 这主要类似于 Unix 和 Windows 路径,如果输入未知命令,则提供查找 DCL 脚本或程序的位置。
例如
$ DEFINE DCL$PATH SYS$DISK:[],SYS$LOGIN:,SYS$SYSTEM:
现在只需输入:TEST this.
海因
此外,如果您需要保留参数的大小写,您必须引用这些参数或输入
$ SET PROCESS/PARSE_STYLE=EXTENDED
在你的进程的生命周期中一次并且
$ DEFINE/USER DECC$ARGV_PARSE_STYLE TRUE
在 运行使用特定的外部命令或使用自动外部命令 (DCL$PATH) 连接您的程序之前。否则所有未加引号的参数都将转换为小写字符。
PS:VMS有命令语言,就是你要给运行一个程序输入命令。默认情况下,文件名不是命令。通过定义 DCL$PATH,您可以更改此默认行为。