Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: running other applications

Subject: running other applications

From: Ender

Date: 5 Jul, 2007 14:15:45

Message: 1 of 32

I trying to run another program through MatLab. I have an example of
how to do this, but whenever I tried running the line of code that I
wrote, but I keep getting the an error.

This is the example code:
/input,start80,NASTRAN,'C:\Program Files\Ansys
Inc\v80\ANSYS\apdl\',,,,,,,,,,,,,,,,1

This is what I wrote:

F=input,startt80,Nastran,'C:\Program
Files\UGS\NXNastran\5.0\bin\Nastran.exe',,,,,,,,,,,,,,,,1 %The path
to run NASTRAN.exe
F

I defined the variable as F because I didn't think that Matlab would
recgonize the "/"

If there is a simpler way to run an excutable program within
Matlab...please let me know.

Reneau

Subject: running other applications

From: Jeremy Smith

Date: 5 Jul, 2007 17:04:55

Message: 2 of 32

Try "!"

You can find more about "!" in the help by searching for "bang". It
should be the second entry listed. If you cannot find it there then
type "doc system". It will be the in the See Also list of functions
at the bottom.

Subject: running other applications

From: Ender

Date: 5 Jul, 2007 19:27:54

Message: 3 of 32

Jeremy Smith wrote:
>
>
> Try "!"
>
> You can find more about "!" in the help by searching for "bang".
> It
> should be the second entry listed. If you cannot find it there
> then
> type "doc system". It will be the in the See Also list of
> functions
> at the bottom.
  

Does MatLab have a command or maybe there is a way that I could write
a function that once I run this other program, I could then get
MatLab to supply the correct input file. Once I run the excutable for
the other program, the program ask for the user to specify the file
that they would like to run. I am going to be doing opening and
reopening this excutable and subsequent open file screen multiple
times. Is there a way that I can tell matlab to keep supplying the
same file name once I excute the bang command and run the other file?
I was thinking that I would have to write a function that places a
certain file into the open file window then excutes that command. Is
that possible?

Subject: running other applications

From: Jeremy Smith

Date: 6 Jul, 2007 09:27:41

Message: 4 of 32

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
'"])

Subject: running other applications

From: Steven Lord

Date: 6 Jul, 2007 09:46:01

Message: 5 of 32


"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))


--
Steve Lord
slord@mathworks.com


Subject: running other applications

From: Ender

Date: 6 Jul, 2007 09:53:17

Message: 6 of 32

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))
>
>
> --
> Steve Lord
> slord@mathworks.com
>
>
> What is the 'foo bar' command? Is 'foo bar' the file that I want to
open?

-Ender-

Subject: running other applications

From: Steve.Amphlett@ricardo.com

Date: 6 Jul, 2007 07:19:42

Message: 7 of 32


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...

Subject: running other applications

From: Jeremy Smith

Date: 6 Jul, 2007 13:25:54

Message: 8 of 32

What is the difference between 'system' and '!' besides 'system'
returning results?

Why is there such a strong aversion to using 'eval'? I realize there
is usually a better way of accomplishing the task programmatically
but I tend to see fairly strong opposition to using 'eval' overall.

Subject: running other applications

From: us

Date: 6 Jul, 2007 13:36:47

Message: 9 of 32

Jeremy Smith:
<SNIP evil eval...

> Why is there such a strong aversion to using 'eval'...

one of the more important reasons
- debugging... eval-constructs quickly tend to obfuscate the code
flow and bugs may be very hard to find

also, in most cases, the newly introduced <function handles>
(ie, macros) allow the same flexibility

just two thoughts
us

Subject: running other applications

From: Peter Boettcher

Date: 6 Jul, 2007 13:44:02

Message: 10 of 32

"Jeremy Smith" <smit1729@umn.NOSPAM.edu> writes:

> What is the difference between 'system' and '!' besides 'system'
> returning results?
>
> Why is there such a strong aversion to using 'eval'? I realize there
> is usually a better way of accomplishing the task programmatically
> but I tend to see fairly strong opposition to using 'eval' overall.

Since the string to be eval'd is built dynamically, the MATLAB engine
can't accelerate anything containing an eval. In fact, even the
parsing of the string has to happen as the eval is called, rather
than the entire m-file being preparsed.

There used to be serious issues with the compiler and eval. I think
that stuff has been resolved with the new compiler, but I don't know.

Finally, readability suffers. String concatenation, number-to-string
conversion (also affects performance!), double and quadruple quotes,
etc.


Code that passes through CSSM that uses eval usually indicates one of
several problems:
- Intuitive desire to use sequentially named variables. (Do other
languages like VBasic use this?) Cell arrays are almost always the
best thing to use instead, for performance and readability reasons.
- Not understanding "command/function duality", which lets you replace
"load fname" with "load('fname')"
- Not understanding the difference between literal strings and string
variables (I think related to the former)

A few obvious comparisons:

eval(['A' num2str(i) ' = myfunctioncall(' num2str(i) ');' ]);
A{i} = myfunctioncall(i);

eval(['load ' myfile ';'])
load(myfile);


So there have it. Computationally slow, hard to read/write/maintain,
indicator of deeper programming knowledge issues which I like to think I
can help address.

-Peter

Subject: running other applications

From: Steven Lord

Date: 6 Jul, 2007 13:45:56

Message: 11 of 32


"Ender" <jr147@msstate.edu> wrote in message
news:ef5c942.4@webcrossing.raydaftYaTP...
> Steven Lord wrote:

*snip*

>> 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))
>>
>>
>> --
>> Steve Lord
>> slord@mathworks.com
>>
>>
>> What is the 'foo bar' command? Is 'foo bar' the file that I want to
> open?

Foo and bar are just 'dummy' arguments. I wanted to show how to pass
arguments to the executable.exe that you wanted to call using ! or system,
so I used them as placeholder arguments.

http://en.wikipedia.org/wiki/Foo

--
Steve Lord
slord@mathworks.com


Subject: running other applications

From: Steven Lord

Date: 6 Jul, 2007 14:20:10

Message: 12 of 32


"Jeremy Smith" <smit1729@umn.NOSPAM.edu> wrote in message
news:ef5c942.6@webcrossing.raydaftYaTP...
> What is the difference between 'system' and '!' besides 'system'
> returning results?

Anything, including % (which normally act as comment characters) that
appears after ! on the command line or on a line of a script or a function
is passed verbatim to the system. In this example, it's as though you typed
"callFoo % This attempts to call the callFoo function" (without the quotes)
at the system command prompt.

!callFoo % This attempts to call the callFoo function

With SYSTEM, you control exactly what gets passed to the system. This
example just passes "callFoo" to the system to be executed.

system('callFoo') % This attempts to call the callFoo function

> Why is there such a strong aversion to using 'eval'? I realize there
> is usually a better way of accomplishing the task programmatically
> but I tend to see fairly strong opposition to using 'eval' overall.

In my opinion (and the opinions of lots of other posters) it's much harder
to read something like:

n = 10;
eval(sprintf('a%d = 1:%d', n, n))

than to read:

a{n} = 1:n

EVAL can also be a very good code obfuscation tool.

http://en.wikipedia.org/wiki/Obfuscated_code

--
Steve Lord
slord@mathworks.com


Subject: running other applications

From: Ralph Schleicher

Date: 6 Jul, 2007 22:25:35

Message: 13 of 32

Peter Boettcher <boettcher@ll.mit.edu> writes:

> Code that passes through CSSM that uses eval usually indicates one of
> several problems:

Real programmers require eval because of:

- Command/function duality, i.e. 'foo bar [1 2; 3 4]' should be
  equal to foo('bar', [1 2; 3 4]). Therefore,

    function foo(a, b)
      a = foo_eval(a);
      b = foo_eval(b);
      % More stuff...

    function val = foo_eval(arg)
      if exist(arg)
        val = arg;
      else
        val = evalin('base', arg, 'arg');
      end

- Feature checking:

    if ~ eval('foo(''bar'')', '0')
      error('Require at least Foo version 2.0');
    end

  There is no existin:

    if ~ evalin('base', sprintf('exist(''%s'', ''var'')', var))
      error(sprintf('Variable ''%s'' does not exist in the Matlab workspace', var));
    end

- Parsing tricks:

    str = getenv('PATH');
    str = strrep(str, '''', '''''');
    str = strrep(str, ':', '''; ''');
    str = eval(['{''', str, '''}']);

  And another one, a Matlab lexer:

    function tok = mlex(str)
      eval(['mlex1 ', str, ' ;']);
      % It's magic!
      tok = ans;

    function arg = mlex1(varargin)
      arg = varargin;

The lexer is my favorite, took me some time to work it out.

> So there have it. Computationally slow,

I like eval, but this is probably related to my Lisp background.

--
Ralph

Lisp programmers know the value of everything and the cost of nothing.

Subject: running other applications

From: us

Date: 6 Jul, 2007 17:10:46

Message: 14 of 32

Ralph Schleicher:
<SNIP a very seasoned CSSMer fighting for <eval>...

> And another one, a Matlab lexer:
> function tok = mlex(str)
> eval(['mlex1 ', str, ' ;']);
> % It's magic!
> tok = ans;
> function arg = mlex1(varargin)
> arg = varargin;
> The lexer is my favorite, took me some time to work it out...

hmmmm...

% let's put this code into <mlex.m>
% run
     mlex 'this is a test'
% ans = 'this' 'is' 'a' 'test'

% -but-
     strread('this is a test','%s').'
% ans = 'this' 'is' 'a' 'test'

most likely, however, i'm missing something...
best from zurich
urs

ps: just one of the counter-examples... :-)

Subject: running other applications

From: Gautam Vallabha

Date: 6 Jul, 2007 17:41:20

Message: 15 of 32


Furthermore problems with mlex (which is a nice party trick, I admit):

>> mlex 'asd b sdf sd f'
ans =
    'asd' 'b' 'sdf' 'sd' 'f'

% So far so good, but ...
% semicolons, single quotes, commas and percent markers all cause mlex to
break:

>> mlex 'asd b sdf sd f; sdfa'
??? Error using ==> eval
Undefined function or variable 'sdfa'.

Error in ==> mlex at 2
      eval(['mlex1 ', str, ' ;']);

>> mlex 'asd b sdf sd f'' sdfa'
??? Error: A MATLAB string constant is not terminated properly.

Error in ==> mlex at 2
      eval(['mlex1 ', str, ' ;']);

>> mlex 'asd b sdf sd f, sdfa'
ans =
    'asd' 'b' 'sdf' 'sd' 'f'
??? Error using ==> eval
Undefined function or variable 'sdfa'.

Error in ==> mlex at 2
      eval(['mlex1 ', str, ' ;']);

>> mlex 'asd b sdf sd f% sdfa'
ans =
    'asd' 'b' 'sdf' 'sd' 'f'
ans =
    'asd' 'b' 'sdf' 'sd' 'f'


------------------
Also, try this:

>> str = ['a b c; ' char(13) 'quit']
>> mlex(str)

I hope no one is using MLEX to implement a CGI script ...

--

Gautam Vallabha
The MathWorks
Email: Gautam.Vallabha@mathworks.com


"us" <us@neurol.unizh.ch> wrote in message
news:ef5c942.12@webcrossing.raydaftYaTP...
> Ralph Schleicher:
> <SNIP a very seasoned CSSMer fighting for <eval>...
>
>
> % let's put this code into <mlex.m>
> % run
> mlex 'this is a test'
> % ans = 'this' 'is' 'a' 'test'
>
> % -but-
> strread('this is a test','%s').'
> % ans = 'this' 'is' 'a' 'test'
>
> most likely, however, i'm missing something...
> best from zurich
> urs
>
> ps: just one of the counter-examples... :-)


Subject: running other applications

From: us

Date: 6 Jul, 2007 18:05:23

Message: 16 of 32

Gautam Vallabha:
<SNIP down to complete, absolutely unexpected, utter, nasty
devastation of a man's ML-mind... -or- was it an evil-eval attack...

> Also, try this:
>>> str = ['a b c; ' char(13) 'quit']
>>> mlex(str)

i did <it> - and - oh my G... ML <quit>... why!?
i must say you're one nasty fellow, <gautam>...
but fortunately, <us>'s solution yields a user-friendly

     s=['a b c; ' char(13) 'quit'].';
     strread(s,'%s').'
% ans = 'a' 'b' 'c;' 'quit'

as always, with a bit of a :-)
us

Subject: running other applications

From: Ralph Schleicher

Date: 7 Jul, 2007 07:23:03

Message: 17 of 32

us <us@neurol.unizh.ch> writes:

> hmmmm...
>
> % let's put this code into <mlex.m>
> % run
> mlex 'this is a test'
> % ans = 'this' 'is' 'a' 'test'
>
> % -but-
> strread('this is a test','%s').'
> % ans = 'this' 'is' 'a' 'test'
>
> most likely, however, i'm missing something...

Yes, you do. Try this:

  mlex('foo -bar ''baz'' [1 2; 3 4]')

Now imagine you want to parse a configuration file of the form

  move -x 650 -y 50
  signal -newline -anchor '=' -string 'Ma =@#.###'
  signal -newline -anchor '=' -string 'p_{amb} =@#.### bar' -tex
  signal -newline -anchor '=' -string 'T_{amb} =@###.# °C' -tex

  tok = mlex(input_line);
  command = tok{1};
  tok(1) = [];
  % Sanity checks..., then
  feval(['do_', command], tok{:});

--
Ralph

Subject: running other applications

From: Ender

Date: 23 Jul, 2007 11:58:21

Message: 18 of 32

I have another question. I tried the command that someone stated
earlier to run another program through MatLab. My program that I am
trying to run can be run through the M-Dos prompt to answer the
question that someone stated earlier. My lines of code look like
this.

Ex.

FileName='D:\Program File\path\path\foo.txt';
eval(['! "C:\Program Files\path\path\path\path\foo.exe" "
FileName"']);

Whenever I try to run this code in my program, the entire program
will complete a run, but the lines of code to open this above stated
file does not. I get this error on the command screen.

*** USER FATAL MESSAGE (pgm: nastran, fn: main)
    jid=FileName (command line[1])
 
    This file does not exist.

Also is there a way that I can tell MatLab to open 'foo.exe'
regardless of the path. That way when I compile my program then send
it to another computer I won't have to rewrite the path to the
'file.exe'

I was thinking that maybe there was a search and find command in
MatLab

Subject: running other applications

From: Steven Lord

Date: 23 Jul, 2007 12:36:36

Message: 19 of 32


"Ender" <jr147@msstate.edu> wrote in message
news:ef5c942.16@webcrossing.raydaftYaTP...
>I have another question. I tried the command that someone stated
> earlier to run another program through MatLab. My program that I am
> trying to run can be run through the M-Dos prompt to answer the
> question that someone stated earlier. My lines of code look like
> this.
>
> Ex.
>
> FileName='D:\Program File\path\path\foo.txt';
> eval(['! "C:\Program Files\path\path\path\path\foo.exe" "
> FileName"']);

EVAL and ! are the wrong tools for this job.

> Whenever I try to run this code in my program, the entire program
> will complete a run, but the lines of code to open this above stated
> file does not. I get this error on the command screen.
>
> *** USER FATAL MESSAGE (pgm: nastran, fn: main)
> jid=FileName (command line[1])
>
> This file does not exist.

You're calling foo.exe with the string "FileName" as the input. In order to
call the function with the contents of the FileName variable as input, use:

system(['"c:\Program Files\path\path\path\path\foo.exe" "' FileName '"'])

or, perhaps a bit clearer:

foo = 'c:\Program Files\path\path\path\path\foo.exe';
FileName='D:\Program File\path\path\foo.txt';
command = sprintf('"%s" "%s"', foo, FileName);
system(command)

> Also is there a way that I can tell MatLab to open 'foo.exe'
> regardless of the path. That way when I compile my program then send
> it to another computer I won't have to rewrite the path to the
> 'file.exe'

If foo.exe is on your system path (which is distinct from the MATLAB path),
SYSTEM should be able to call it.

--
Steve Lord
slord@mathworks.com


Subject: running other applications

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 23 Jul, 2007 16:39:56

Message: 20 of 32

In article <ef5c942.16@webcrossing.raydaftYaTP>,
Ender <jr147@msstate.edu> wrote:

>Ex.

>FileName='D:\Program File\path\path\foo.txt';
>eval(['! "C:\Program Files\path\path\path\path\foo.exe" "
>FileName"']);

eval(['! "C:\Program Files\path\path\path\path\foo.exe" "' ...
     FileName ...
     '"']);

You have to end the '' string in order to have a variable's
value concatenated on by the [] operator. Your current
expression is equivilent to not having the [] there at all and just
having one long '' string.
--
  Is there any thing whereof it may be said, See, this is new? It hath
  been already of old time, which was before us. -- Ecclesiastes

Subject: running other applications

From: Ender

Date: 23 Jul, 2007 14:18:36

Message: 21 of 32

>
> "If foo.exe is on your system path (which is distinct from the
> MATLAB path),
> SYSTEM should be able to call it."

Could you explain this statment? What do mean by system path?

>
> -Ender-
>

Subject: running other applications

From: us

Date: 23 Jul, 2007 20:59:03

Message: 22 of 32

Ender:
<SNIP from ML to OS...

> What do mean by system path...

it's the <search path> of your operating system (OS), eg, windows 95, dos 3.1, etc - or - the OS's equivalent of ML's <path>...

see

     help getenv;
% -and- in particular
     getenv('PATH')

us

Subject: running other applications

From: Ender

Date: 24 Jul, 2007 13:17:20

Message: 23 of 32

us wrote:
>
>
> Ender:
> <SNIP from ML to OS...
>
>> What do mean by system path...
>
> it's the <search path> of your operating system (OS), eg,
> windows 95, dos 3.1, etc - or - the OS's equivalent of ML's
> <path>...
>
> see
>
> help getenv;
> % -and- in particular
> getenv('PATH')
>
> us
  

I am still confused about this. I typed in the above command in the
MatLab command window. When I hit enter I got this :

C:\MATLAB7\bin\win32;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system3
2\wbem;c:\program files\ivi\bin...

plust alot more subdirectories. I don't understand what this means or
what this is telling me. Does this system path allow me to find the
path to a file regardless of the path. Meaning if I am looking for a
certain program on a computer that is different from mine, as long as
I state the file that I am looking for will MatLab look through the
computer until it finds the file, or do I have to specify the path?

-Ender-

Subject: running other applications

From: Ender

Date: 24 Jul, 2007 13:27:50

Message: 24 of 32

us wrote:
>
>
> Ender:
> <SNIP from ML to OS...
>
>> What do mean by system path...
>
> it's the <search path> of your operating system (OS), eg,
> windows 95, dos 3.1, etc - or - the OS's equivalent of ML's
> <path>...
>
> see
>
> help getenv;
> % -and- in particular
> getenv('PATH')
>
> us
  

I am still confused about this. I typed in the above command in the
MatLab command window. When I hit enter I got this :

C:\MATLAB7\bin\win32;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system3
2\wbem;c:\program files\ivi\bin...

plust alot more subdirectories. I don't understand what this means or
what this is telling me. Does this system path allow me to find the
path to a file regardless of the path. Meaning if I am looking for a
certain program on a computer that is different from mine, as long as
I state the file that I am looking for will MatLab look through the
computer until it finds the file, or do I have to specify the path?

-Ender-

Subject: running other applications

From: Steven Lord

Date: 24 Jul, 2007 13:42:44

Message: 25 of 32


"Ender" <jr147@msstate.edu> wrote in message
news:ef5c942.21@webcrossing.raydaftYaTP...
> us wrote:
>>
>>
>> Ender:
>> <SNIP from ML to OS...
>>
>>> What do mean by system path...
>>
>> it's the <search path> of your operating system (OS), eg,
>> windows 95, dos 3.1, etc - or - the OS's equivalent of ML's
>> <path>...
>>
>> see
>>
>> help getenv;
>> % -and- in particular
>> getenv('PATH')
>>
>> us
>
>
> I am still confused about this. I typed in the above command in the
> MatLab command window. When I hit enter I got this :
>
> C:\MATLAB7\bin\win32;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system3
> 2\wbem;c:\program files\ivi\bin...
>
> plust alot more subdirectories. I don't understand what this means or
> what this is telling me. Does this system path allow me to find the
> path to a file regardless of the path.

If the executable that you want to execute is in a directory that is on your
system path, then you will not need to provide the full path to that
executable when you use the SYSTEM function or run it from the Windows
command line. To borrow the Wikipedia definition, your system path is the
set of directories where your computer's operating system will search for
executables.

For instance, you probably have an executable write.exe in your
c:\windows\system32 directory. Because this directory is on your system
path, you can use this command to execute it:

system('write')

instead of needing to use:

system('c:\windows\system32\write')

Windows will search each directory in your system path until it finds a file
named write, and will execute that program when Windows finds it in one of
those directories.

--
Steve Lord
slord@mathworks.com


Subject: running other applications

From: z khan

Date: 24 Jul, 2007 20:55:40

Message: 26 of 32

"Steven Lord" <slord@mathworks.com> wrote in message <f85dmk$p12$1@fred.mathworks.com>...
>
> "Ender" <jr147@msstate.edu> wrote in message
> news:ef5c942.21@webcrossing.raydaftYaTP...
> > us wrote:
> >>
> >>
> >> Ender:
> >> <SNIP from ML to OS...
> >>
> >>> What do mean by system path...
> >>
> >> it's the <search path> of your operating system (OS), eg,
> >> windows 95, dos 3.1, etc - or - the OS's equivalent of ML's
> >> <path>...
> >>
> >> see
> >>
> >> help getenv;
> >> % -and- in particular
> >> getenv('PATH')
> >>
> >> us
> >
> >
> > I am still confused about this. I typed in the above command in the
> > MatLab command window. When I hit enter I got this :
> >
Try
winopen('C:\.....abc.exe');

> > C:\MATLAB7\bin\win32;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system3
> > 2\wbem;c:\program files\ivi\bin...
> >
> > plust alot more subdirectories. I don't understand what this means or
> > what this is telling me. Does this system path allow me to find the
> > path to a file regardless of the path.
>
> If the executable that you want to execute is in a directory that is on your
> system path, then you will not need to provide the full path to that
> executable when you use the SYSTEM function or run it from the Windows
> command line. To borrow the Wikipedia definition, your system path is the
> set of directories where your computer's operating system will search for
> executables.
>
> For instance, you probably have an executable write.exe in your
> c:\windows\system32 directory. Because this directory is on your system
> path, you can use this command to execute it:
>
> system('write')
>
> instead of needing to use:
>
> system('c:\windows\system32\write')
>
> Windows will search each directory in your system path until it finds a file
> named write, and will execute that program when Windows finds it in one of
> those directories.
>
> --
> Steve Lord
> slord@mathworks.com
>
>

Subject: running other applications

From: Ender

Date: 25 Jul, 2007 11:34:28

Message: 27 of 32

> Try
> winopen('C:\.....abc.exe');

I tried this above command with the excutable that I was trying to
run and it didn't work. MatLab said that

??? Error using ==> winopen
The specified file does not exist.

>> If the executable that you want to execute is in a directory
that
> is on your
>> system path, then you will not need to provide the full path to
> that
>> executable when you use the SYSTEM function or run it from the
> Windows
>> command line. To borrow the Wikipedia definition, your system
> path is the
>> set of directories where your computer's operating system will
> search for
>> executables.
>>
>> For instance, you probably have an executable write.exe in your
>> c:\windows\system32 directory. Because this directory is on
your
> system
>> path, you can use this command to execute it:
>>
>> system('write')
>>
>> instead of needing to use:
>>
>> system('c:\windows\system32\write')
>>
>> Windows will search each directory in your system path until it
> finds a file
>> named write, and will execute that program when Windows finds
it
> in one of
>> those directories.
>>

Windows must first know which path to search in to find the file? I
can't just type system('write.exe') without first initially stating
where foo.exe is. So when you say "Windows will search each directory
in your system path until it
> finds a file
>> named "write" I would first have to state the correct path to
write.exe. There is no command that lets me just state the file
without first stating the path to the file?

-Ender-

Subject: running other applications

From: Josh

Date: 29 Feb, 2008 17:20:17

Message: 28 of 32

Ender <jr147@msstate.edu> wrote in message
<ef5c942.25@webcrossing.raydaftYaTP>...
> > Try
> > winopen('C:\.....abc.exe');
>
> I tried this above command with the excutable that I was
trying to
> run and it didn't work. MatLab said that
>
> ??? Error using ==> winopen
> The specified file does not exist.
>
> >> If the executable that you want to execute is in a
directory
> that
> > is on your
> >> system path, then you will not need to provide the
full path to
> > that
> >> executable when you use the SYSTEM function or run it
from the
> > Windows
> >> command line. To borrow the Wikipedia definition, your
system
> > path is the
> >> set of directories where your computer's operating
system will
> > search for
> >> executables.
> >>
> >> For instance, you probably have an executable
write.exe in your
> >> c:\windows\system32 directory. Because this directory
is on
> your
> > system
> >> path, you can use this command to execute it:
> >>
> >> system('write')
> >>
> >> instead of needing to use:
> >>
> >> system('c:\windows\system32\write')
> >>
> >> Windows will search each directory in your system path
until it
> > finds a file
> >> named write, and will execute that program when
Windows finds
> it
> > in one of
> >> those directories.
> >>
>
> Windows must first know which path to search in to find
the file? I
> can't just type system('write.exe') without first
initially stating
> where foo.exe is. So when you say "Windows will search
each directory
> in your system path until it
> > finds a file
> >> named "write" I would first have to state the correct
path to
> write.exe. There is no command that lets me just state
the file
> without first stating the path to the file?
>
> -Ender-


I have been trying to execute this program for matlab using
the advice above but I keep getting this error:

status =

   128


result =

     ''

The code does not execute the program.

My m-code looks as following:

icExe = 'C:\PathName\myProgram.exe';
FullImg = ['-i', ' ', FullImg, ' '];
FullSens = ['-bi', ' ', FullSens, ' '];
FullAA = ['-co', ' ', FullAA, ' '];
                    
cmdLine = [FullImg, FullSens, FullAA];
cmdLine = sprintf('%s %s', icExe, cmdLine)
                    
[status,result] = system(cmdLine)

Any help on why this doesnt work?

Thanks1

Subject: running other applications

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 29 Feb, 2008 17:28:08

Message: 29 of 32

In article <fq9esh$ojv$1@fred.mathworks.com>,
Josh <imahorse3@hotmail.com> wrote:

>I have been trying to execute this program for matlab using
>the advice above but I keep getting this error:

>status =
> 128
>result =
> ''

>icExe = 'C:\PathName\myProgram.exe';
>FullImg = ['-i', ' ', FullImg, ' '];
>FullSens = ['-bi', ' ', FullSens, ' '];
>FullAA = ['-co', ' ', FullAA, ' '];

>cmdLine = [FullImg, FullSens, FullAA];
>cmdLine = sprintf('%s %s', icExe, cmdLine)

As a stylistic note: if you use [] to splice together character
strings on the lines above this, but then use sprintf to splice
together character strings here, then it may give the onlooker
the impression that there is something different about the
respective operations, and the onlooker may then waste time trying
to figure out what the distinction in meaning is. It is thus
advisable to be consistant, such as by coding

cmdLine = [icExe, ' ', cmdLine];

instead of using the sprintf.


>[status,result] = system(cmdLine)

>Any help on why this doesnt work?

There is nothing that is obvious to me in what you show.
However, not knowing the starting values of FullImg, FullSens, or FullAA,
I would speculate that perhaps one of them has a special character
(such as a space or '>') that needs to be quoted to be passed intact
to the command line. Possibly something like,

FullImg = ['-i', ' "', FullImg, '" '];
--
  "You can't hit what you can't see." -- Walter "The Big Train" Johnson

Subject: running other applications

From: Josh

Date: 29 Feb, 2008 17:37:01

Message: 30 of 32

roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
message <fq9fb8$s9b$1@canopus.cc.umanitoba.ca>...
> In article <fq9esh$ojv$1@fred.mathworks.com>,
> Josh <imahorse3@hotmail.com> wrote:
>
> >I have been trying to execute this program for matlab
using
> >the advice above but I keep getting this error:
>
> >status =
> > 128
> >result =
> > ''
>
> >icExe = 'C:\PathName\myProgram.exe';
> >FullImg = ['-i', ' ', FullImg, ' '];
> >FullSens = ['-bi', ' ', FullSens, ' '];
> >FullAA = ['-co', ' ', FullAA, ' '];
>
> >cmdLine = [FullImg, FullSens, FullAA];
> >cmdLine = sprintf('%s %s', icExe, cmdLine)
>
> As a stylistic note: if you use [] to splice together
character
> strings on the lines above this, but then use sprintf to
splice
> together character strings here, then it may give the
onlooker
> the impression that there is something different about the
> respective operations, and the onlooker may then waste
time trying
> to figure out what the distinction in meaning is. It is
thus
> advisable to be consistant, such as by coding
>
> cmdLine = [icExe, ' ', cmdLine];
>
> instead of using the sprintf.
>
>
> >[status,result] = system(cmdLine)
>
> >Any help on why this doesnt work?
>
> There is nothing that is obvious to me in what you show.
> However, not knowing the starting values of FullImg,
FullSens, or FullAA,
> I would speculate that perhaps one of them has a special
character
> (such as a space or '>') that needs to be quoted to be
passed intact
> to the command line. Possibly something like,
>
> FullImg = ['-i', ' "', FullImg, '" '];
> --
> "You can't hit what you can't see." -- Walter "The Big
Train" Johnson


OK, I will take your advice about the style, thanks.

The 3 variables (FullImg, FullSens, FullAA) are simply
pathname\filename combinations as selected by the user.

An example: FullImg = C:\Users\joshua\ic\testcase\eglin.img

The other variables are the same.

Does this change anything?

Subject: running other applications

From: Josh

Date: 29 Feb, 2008 18:50:23

Message: 31 of 32

"Josh " <imahorse3@hotmail.com> wrote in message
<fq9frt$aqp$1@fred.mathworks.com>...
> roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
> message <fq9fb8$s9b$1@canopus.cc.umanitoba.ca>...
> > In article <fq9esh$ojv$1@fred.mathworks.com>,
> > Josh <imahorse3@hotmail.com> wrote:
> >
> > >I have been trying to execute this program for matlab
> using
> > >the advice above but I keep getting this error:
> >
> > >status =
> > > 128
> > >result =
> > > ''
> >
> > >icExe = 'C:\PathName\myProgram.exe';
> > >FullImg = ['-i', ' ', FullImg, ' '];
> > >FullSens = ['-bi', ' ', FullSens, ' '];
> > >FullAA = ['-co', ' ', FullAA, ' '];
> >
> > >cmdLine = [FullImg, FullSens, FullAA];
> > >cmdLine = sprintf('%s %s', icExe, cmdLine)
> >
> > As a stylistic note: if you use [] to splice together
> character
> > strings on the lines above this, but then use sprintf
to
> splice
> > together character strings here, then it may give the
> onlooker
> > the impression that there is something different about
the
> > respective operations, and the onlooker may then waste
> time trying
> > to figure out what the distinction in meaning is. It is
> thus
> > advisable to be consistant, such as by coding
> >
> > cmdLine = [icExe, ' ', cmdLine];
> >
> > instead of using the sprintf.
> >
> >
> > >[status,result] = system(cmdLine)
> >
> > >Any help on why this doesnt work?
> >
> > There is nothing that is obvious to me in what you show.
> > However, not knowing the starting values of FullImg,
> FullSens, or FullAA,
> > I would speculate that perhaps one of them has a
special
> character
> > (such as a space or '>') that needs to be quoted to be
> passed intact
> > to the command line. Possibly something like,
> >
> > FullImg = ['-i', ' "', FullImg, '" '];
> > --
> > "You can't hit what you can't see." -- Walter "The
Big
> Train" Johnson
>
>
Nevermind, I had to change the environment variables on my
system. Duh.

Thanks anyway.

Subject: running other applications

From: Ashish Uthama

Date: 29 Feb, 2008 19:26:42

Message: 32 of 32

which one? Am a bit puzzled too..


On Fri, 29 Feb 2008 13:50:23 -0500, Josh <imahorse3@hotmail.com> wrote:=


> "Josh " <imahorse3@hotmail.com> wrote in message
> <fq9frt$aqp$1@fred.mathworks.com>...
>> roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
>> message <fq9fb8$s9b$1@canopus.cc.umanitoba.ca>...
>> > In article <fq9esh$ojv$1@fred.mathworks.com>,
>> > Josh <imahorse3@hotmail.com> wrote:
>> >
>> > >I have been trying to execute this program for matlab
>> using
>> > >the advice above but I keep getting this error:
>> >
>> > >status =3D
>> > > 128
>> > >result =3D
>> > > ''
>> >
>> > >icExe =3D 'C:\PathName\myProgram.exe';
>> > >FullImg =3D ['-i', ' ', FullImg, ' '];
>> > >FullSens =3D ['-bi', ' ', FullSens, ' '];
>> > >FullAA =3D ['-co', ' ', FullAA, ' '];
>> >
>> > >cmdLine =3D [FullImg, FullSens, FullAA];
>> > >cmdLine =3D sprintf('%s %s', icExe, cmdLine)
>> >
>> > As a stylistic note: if you use [] to splice together
>> character
>> > strings on the lines above this, but then use sprintf
> to
>> splice
>> > together character strings here, then it may give the
>> onlooker
>> > the impression that there is something different about
> the
>> > respective operations, and the onlooker may then waste
>> time trying
>> > to figure out what the distinction in meaning is. It is
>> thus
>> > advisable to be consistant, such as by coding
>> >
>> > cmdLine =3D [icExe, ' ', cmdLine];
>> >
>> > instead of using the sprintf.
>> >
>> >
>> > >[status,result] =3D system(cmdLine)
>> >
>> > >Any help on why this doesnt work?
>> >
>> > There is nothing that is obvious to me in what you show.
>> > However, not knowing the starting values of FullImg,
>> FullSens, or FullAA,
>> > I would speculate that perhaps one of them has a
> special
>> character
>> > (such as a space or '>') that needs to be quoted to be
>> passed intact
>> > to the command line. Possibly something like,
>> >
>> > FullImg =3D ['-i', ' "', FullImg, '" '];
>> > --
>> > "You can't hit what you can't see." -- Walter "The
> Big
>> Train" Johnson
>>
>>
> Nevermind, I had to change the environment variables on my
> system. Duh.
>
> Thanks anyway.

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
help wiht tcpip connections Kazi 17 Mar, 2008 19:41:17
os Santosh Kasula 1 Aug, 2007 13:43:40
system Patrick HannaSecure 25 Jul, 2007 16:24:00
os Patrick HannaSecure 25 Jul, 2007 16:23:56
external Patrick HannaSecure 25 Jul, 2007 16:23:51
os us 23 Jul, 2007 21:19:31
operating system us 23 Jul, 2007 21:19:31
system Matthew Simoneau 11 Jul, 2007 13:40:41
external Matthew Simoneau 11 Jul, 2007 13:40:41
rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics