[comp.lang.c] Command line parameters with VAX C?

LC.YRS@forsythe.stanford.edu (Richard Stanton) (01/03/90)

Using C on my PC, I can pass command line parameters to programs via
the simple:

progname [parameter list]

On a VAX, I type cc [progname] to compile, link [progname...] to
link, and "run progname" to run a program. How do I pass command
line parameters (file names etc) to a program under this system? If
I type

run progname parmlist

I get a message complaining that RUN is being given too many
parameters. HELP RUN is not too informative.

Thanks

Richard Stanton

pstanton@gsb-what.stanford.edu

dona@ncr-fc.FtCollins.NCR.com (Don Allingham) (01/03/90)

On 2 Jan 90 18:56:18 GMT,
LC.YRS@forsythe.stanford.edu (Richard Stanton) said:

Richard> Using C on my PC, I can pass command line parameters to programs via
Richard> the simple:

Richard> progname [parameter list]

Richard> On a VAX, I type cc [progname] to compile, link [progname...] to
Richard> link, and "run progname" to run a program. How do I pass command
Richard> line parameters (file names etc) to a program under this system? If
Richard> I type

Richard> run progname parmlist

Richard> I get a message complaining that RUN is being given too many
Richard> parameters. HELP RUN is not too informative.

Richard> Thanks

Richard> Richard Stanton

Richard> pstanton@gsb-what.stanford.edu


VMS does things a little different than the UNIX/PC world.  Basically,
you need to define a symbol.  For the program foo.exe, you would have
to do:

	foo :== $disk:[directory]foo.exe

The $ is required.  disk is the disk name, directory is the VMS
directory path.  Command line arguments will now be understood.  Note
that in VMSland, this definition lasts only for the current login
session, so you would want to put the definition in your login.com
file, or have your system administrator enter it in one of the start
up files.

(No, I am not a VMS guru.  VMS is a necessary evil in my UNIX world.)

--
Don Allingham           
NCR Microelectronics 			ncr-fc!bach!dona@ccncsu.colostate.edu 
Ft. Collins, CO.        		...!ncr-sd!ncr-fc!bach!dona

nboogaar@ruunsa.fys.ruu.nl (Martin v.d. Boogaard) (01/03/90)

There are two ways to do the job. 

  1. Use argc and argv like you do on any other system. You saw that you can't
     type 

       RUN MYCODE PAR1 PAR2 <ret>

     because RUN expects only the name of the executable it should load. The 
     simple solution is to define (e.g. in LOGIN.COM)

       MYC*ODE :== $MYCODE <ret>

     which enables you to simply enter

       MYCODE PAR1 PAR2 <ret>

  2. The complicated way is to use the Command Definition Utility (CDU) to
     install a command MYCODE that takes two parameters and runs MYCODE.EXE .
     You can specify default values and options and check whether parameter
     values are filenames or numbers etc.  I use this to parse command
     line parameters to Pascal code because in VAX Pascal there is no such
     thing as argv . You have to use the routines CLI$PRESENT and CLI$GET_VALUE
     to find out about the values of your command line parameters. Off course
     the parameters off these system routines are passed by means of the usual
     string descriptor, which means you'll have to define a structure to match
     the VMS definition off this descriptor.

Solution #1 is quick and will solve many problems, #2 is very non-portable,
rather time consuming, but is to be preferred if you don't want your code to 
do the initial parameter checking.

Contact me directly if you need examples of the use of CDU or the application
of CLI$... 


Martin J. van den Boogaard          
                                        
Dept. of Atomic & Interface Physics, Rijksuniversiteit, Utrecht

                                       P.O. Box 80.000
DecNet:   ruunsc::boogaard             NL-3508 TA  Utrecht
BitNet:   boogaard@hutruu51.bitnet     the Netherlands
internet: nboogaar@fys.ruu.nl          +31 30 532904

barsh@stsci.EDU (John Barshinger) (01/03/90)

From article <6808@lindy.Stanford.EDU>, by LC.YRS@forsythe.stanford.edu (Richard Stanton):
> Using C on my PC, I can pass command line parameters to programs via
> the simple:
> 
> progname [parameter list]
> 
> On a VAX, I type cc [progname] to compile, link [progname...] to
> link, and "run progname" to run a program. How do I pass command
> line parameters (file names etc) to a program under this system? If
> I type
> 
> run progname parmlist
> 
> I get a message complaining that RUN is being given too many
> parameters. HELP RUN is not too informative.
> 
> Thanks
> 
> Richard Stanton
> 
> pstanton@gsb-what.stanford.edu

To use the argv,argc convention in VAX C, you must define the
C program as a foreign command.

EXAMPLE:

$ fred :== $disk$fred:[fred]fred

this will make the program fred in directory fred on disk$fred a foreign
command (don't forget the initial $ in front of the disk name, it's
very important)

to run the program, type:

$ fred arglist

this will pass in the parameters to the c program.


jrbii
-- 
	        John Barshinger	
		Space Telescope Science Institute
		Baltimore, MD 21218
		plink:jrbii | bix:jrbii | barsh@stsci.edu

cns@stiatl.UUCP (Chris Straut) (01/03/90)

In article <6808@lindy.Stanford.EDU> LC.YRS@forsythe.stanford.edu (Richard Stanton) writes:
>Using C on my PC, I can pass command line parameters to programs via
>the simple:
>
>progname [parameter list]
>
>How do I pass command line parameters (file names etc) to a program under
>this system? If I type
>
>run progname parmlist
>
>I get a message complaining that RUN is being given too many
>parameters. HELP RUN is not too informative.
>
>Thanks
>
>Richard Stanton

To get a VAX/VMS image to accept command line arguments you need to
declare the executable as a foreign command.  This is done as follows:

FRED :== $ userdisk:[userdir]FRED.EXE - where FRED.EXE is the executable.

Then the command line would look like the following:

$ FRED parameter1  parameter2 ...

where $ is the VAX/VMS prompt.  FRED is now a symbol in your process table
and can be examined by SHOW SYMBOL FRED.  The '$' in the definition is 
required for declaring executables as foreign commands.

These symbols can be used on command procedures as well, and save you
from typing the '@' character each type.  It is similar to the symbols
used for executables.

FRED :== @userdisk:[userdir]FRED.COM - where FRED.COM is the command proc.

The command line would then look like the following:

FRED parameter1 parameter2 ...

All of your most commonly used commands could be declared in LOGIN.COM or
a SYMBOLS.COM file to avoid keying in each type you start a VAX/VMS session. 

Hope this clears things up a little.



-- 
Christopher Straut             | Go Jackets!!!!!         gatech!stiatl!cns
Sales Technologies, Inc        |
3399 Peachtree Rd, NE          |
Atlanta, GA  (404) 841-4000    |

minow@mountn.dec.com (Martin Minow) (01/04/90)

Here's a simple way to define C executables as foreign commands with
a minimum of typing:

First, create the following command file (put it in your login directory
for convenience, calling it NAME.COM)

	$! make X.exe in the current directory into a foreign command
	$ if "''p1'" .eqs. "" then write sys$output "How can I name nothing?"
	$ 'p1' :== $'f$environment("DEFAULT")''p1'.exe

Now, edit your LOGIN.COM to define NAME.COM as a foreign command:

	$ name :== @sys$login:name.com

Now, after you link a program, you can turn it into a foreign command by

	$ link foo...
	$ name foo
	$ foo arg1 arg2 etc.

Hope this helps.

Martin Minow
minow@thundr.enet.dec.com

chris@sunset.ncsl.nist.gov (Chris Schanzle) (01/05/90)

minow@mountn.dec.com (Martin Minow) writes:
>Here's a simple way to define C executables as foreign commands with
>a minimum of typing:

[ugly procedure that I don't fully understand thanks to my ignorance on vms.]
>Martin Minow
>minow@thundr.enet.dec.com

Recently I had to write a program that was 100% portable on Unix,
Puke-Dos, and of course, VMS.  Obviously, I ran into the brain-damaged
run command in VMS also.  I was hoping someone would post more
information, rather than a procedure with little explanation.

My solution was simple:  compile it somewhere you expect it to stay
put and do a $dir command to get the full device and directory name
to build the following command (symbol?):

	$ prog :== $<device>:[<directory>]program.exe

[the "$" before <device> is required.  ".exe" suffix is optional.]

Now when you type "prog" vms will run "program" with any arguments you
give on the command line as argv[argc] parameters.  Chuck this
(single) line into your login.com file and don't worry about it any
longer.  No no fuss, no muss, and no ".com" files.
__________

"I'm gonna need a beer 			Chris Schanzle, Computer Scientist
 to put these flames out..."		Natnl Inst of Stds & Technology
					chris@sunset.ncsl.nist.gov

minow@mountn.dec.com (Martin Minow) (01/05/90)

In article <2457@durer.cme.nbs.gov> chris@sunset.ncsl.nist.gov
(Chris Schanzle) justifiably complains that my "define a foreign command"
procedure is ugly and un-understandable.  Too true.  Just trust me. (:-)
>
>My solution was simple:  compile it somewhere you expect it to stay
>put and do a $dir command to get the full device and directory name
>to build the following command (symbol?):
>
>	$ prog :== $<device>:[<directory>]program.exe
>
>[the "$" before <device> is required.  ".exe" suffix is optional.]
>
Permit me to elaborate slightly.  f$environment("DEFAULT") is a sort of
getenv() in the command language.  DEFAULT is the current device:[directory]
string and the single quotes control variable name evaluation.  My command file
is useful for one-off compilations.  As Chris notes, executables that stay
around should be stored in a consistent place and defined using a one-liner
in your login.com file.  In my case, I have a subdirectory [.bin] and a private
logical BIN: that points to it.  My login.com file then merely says:
	$ grep :== $bin:grep.exe
(I would recommend always including the .exe because of the way logical
name translation works on VMS).

I've directed followups to comp.sys.vms so we stop boring the C folk
with this trivia.

Martin
minow@thundr.enet.dec.com