Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!w3g2000hsg.googlegroups.com!not-for-mail
From:  Steve.Amphlett@ricardo.com
Newsgroups: comp.soft-sys.matlab
Subject: Re: running other applications
Date: Fri, 06 Jul 2007 07:19:42 -0700
Organization: http://groups.google.com
Lines: 41
Message-ID: <1183731582.111910.293480@w3g2000hsg.googlegroups.com>
References: <ef5c942.-1@webcrossing.raydaftYaTP>
NNTP-Posting-Host: 81.134.24.18
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
X-Trace: posting.google.com 1183731582 2781 127.0.0.1 (6 Jul 2007 14:19:42 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Fri, 6 Jul 2007 14:19:42 +0000 (UTC)
In-Reply-To: <f6lh2p$4ie$1@fred.mathworks.com>
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; T312461; iebar; acc=3Dventura5; .NET CLR 2.0.50727),gzip(gfe),gzip(gfe)
X-HTTP-Via: 1.0 SANCHEZ
Complaints-To: groups-abuse@google.com
Injection-Info: w3g2000hsg.googlegroups.com; posting-host=81.134.24.18;
Xref: news.mathworks.com comp.soft-sys.matlab:417586




Steven Lord wrote:
> "Jeremy Smith" <smit1729@umn.NOSPAM.edu> wrote in message
> news:ef5c942.2@webcrossing.raydaftYaTP...
> > It all depends on the program you must run. As far as I know the
> > only way to have a program do what you want it to do from Matlab
> > itself the program must be able to accept command line inputs. I
> > suspect (and could be wrong) any other method, aside from the command
> > line, would involve Java. If, however, your program does accept
> > command lines you can use "eval" along with "!".
> >
> > FileName = 'C:\File Location\File_Name';
> > eval(['! "C:\Program Files\SomeProgram\executable.exe" "' FileName
> > '"])
>
> Don't use EVAL -- you don't need to in this case.  Use SYSTEM, DOS, or UNIX
> instead of !.
>
>
> theprogram = '"C:\Program Files\SomeProgram\executable.exe"';
> thearguments = 'foo bar';
> system(sprintf('%s %s', theprogram thearguments))

I'm not often one to try to amplify posts from Steven Lord, but...

I find the best way to develop this kind of stuff is to use the
following approach:

1) Create your command string using sprintf and/or old-style ML
concatenations.
2) View it.
3) When absolutely sure it's right, system() it.

This generally leaves the following code:

command = sprintf(  % Some stuff
system(command)

I know this seems really trivial, but wrapping system() around
something you're not yet sure about could cause nasal demons...