Article View: vmsnet.misc
Article #156Re: Passing args to C programs
From: 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
Technical Details
Message-ID:
<1992Oct2.081914@mccall.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!wupost!zaphod.mps.ohio-state.edu!moe.ksu.ksu.edu!mccall!mccall!tpReferences:
<1992Oct1.234301.8944@monu6.cc.monash.edu.au>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!wupost!zaphod.mps.ohio-state.edu!moe.ksu.ksu.edu!mccall!mccall!tp Newsgroups: vmsnet.misc Subject: Re: Passing args to C programs Message-ID: <1992Oct2.081914@mccall.com> From: tp@mccall.com (Terry Poot) Date: Fri, 2 Oct 1992 08:19:14 CST Reply-To: tp@mccall.com (Terry Poot) References: <1992Oct1.234301.8944@monu6.cc.monash.edu.au> Organization: The McCall Pattern Co., Manhattan, KS, USA Nntp-Posting-Host: mis1 Nntp-Posting-User: tp Lines: 46