Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1998
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1998

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Install[] and command line args?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg13448] Re: Install[] and command line args?
  • From: kevinl (Kevin Leuthold)
  • Date: Fri, 24 Jul 1998 01:45:35 -0400
  • Organization: Wolfram Research, Inc.
  • References: <6p6q98$5hv@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

lgy at newton.phys.washington.edu (Laurence Yaffe) writes:

>Is there any way to pass command line arguments to an external program
>(created with mcc) which will be started with Mathematica's Install[] ?

>------------------------------------------------------------------------
>Laurence G. Yaffe      yaffe at phys.washington.edu Department of Physics
>University of Washington   1-206-543-3902 (fax: 1-206-543-9523)


Laurence,

Yes, you can pass command-line options to your external program, which I
will show how to do below.  The problem with using Install to do this
is that Install tries to do some guessing of what program you are
trying to launch - by putting quotes around the program in case there's
a space in it, by looking down $Path for your program, and other
things.  This guessing means that passing command line arguments can
sometimes confuse it and cause it to guess wrong.

However, if you are willing to give up those features of Install, and
simply use LinkLaunch to launch your program and call Install on the
returned LinkObject, then you can pass command-line arguments.

For example, let's say you have a program called "/usr/foo/addtwo", and
you want to pass it command-line arguments.  Below, as an example, I've
modified the main  function of addtwo.c to print out its arguments to
stderr:

#include <stdio.h>

int main(int argc, char* argv[])
{
    int i;

    for( i=0; i<argc; i++){
        fprintf( stderr, "%s\n", argv[i]);
    }

    return MLMain(argc, argv);
}

Then from Mathematica, to Install this program with the command -a, you
could do this:

In[1]:= link = LinkLaunch["/usr/foo/addtwo -a"]

Out[1]= LinkObject[/usr/foo/addtwo -a, 1, 1]

In[2]:= Install[link]

Out[2]= LinkObject[/usr/foo/addtwo -a, 1, 1]

or, more simply:

In[1]:= link = Install[LinkLaunch["/usr/foo/addtwo -a"]];

Out[1]= LinkObject[/usr/foo/addtwo -a, 1, 1]


Kevin Leuthold
MathLink Group
Wolfram Research



  • Prev by Date: Re: Q: Graphics3D
  • Next by Date: Re: Is this a bug?
  • Previous by thread: Install[] and command line args?
  • Next by thread: Re: Install[] and command line args?