Thread View: vmsnet.misc
2 messages
2 total messages
Started by Ben Aveling
Thu, 01 Oct 1992 23:43
Passing args to C programs
Author: Ben Aveling
Date: Thu, 01 Oct 1992 23:43
Date: Thu, 01 Oct 1992 23:43
8 lines
656 bytes
656 bytes
This may be the wrong place, but can someone please tell me, how can I pass command-line arguments to a C program. I know how to do it in Unix, or Ultrix, but not VMS. Thanks in anticipation Ben
Re: Passing args to C programs
Author: Terry Poot
Date: Fri, 02 Oct 1992 14:19
Date: Fri, 02 Oct 1992 14:19
46 lines
2209 bytes
2209 bytes
In the C code, everything is the same. However, you have to define a foreign command symbol for your program. For instance, if your executable is dua0:[foo]test.exe, enter foo :== $dua0:[foo]test.exe You can then run your program as: foo arg1 arg2 and the command line arguments will be passed through argc and argv as usual. A few notes: 1) Note the "$" at the beginning of the file spec, it's required. Also, the filespec will default to looking in sys$system for the executable so be sure to use a fully qualified file name (i.e. include the device and directory or some logical name that points to the device and directory. 2) DCL normally forces all unquoted arguments to upper case. The C run-time library counters this by forcing them all to lower case. If you want an argument to be passed in upper or mixed case, you have to quote it, as in: foo "-AaBb" arg1 Arg2 ARG3 "Arg4" In the above, the options string and Arg4 will get through in mixed case, args 1-3 will all be lower case. And don't try the short cut of quoting all the args with one set of quotes, because that will make the whole quoted string one argument. 3) argv[0] is NOT the command typed to run the program, it is the whole fully qualified file name. This can mess up the way most unix programs print their error messages. Of course, your program can do something like: #ifdef VMS argv[0] = "foo" #endif to get around this. Obtw, yes this is the right group for this type of question. -- Terry Poot <tp@mccall.com> The McCall Pattern Company (uucp: ...!rutgers!depot!mccall!tp) 615 McCall Road (800)255-2762, in KS (913)776-4041 Manhattan, KS 66502, USA
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads