MATLAB Answers

Jorge
0

Can I run a bat file with Matlab?

Asked by Jorge
on 27 Jan 2011
Latest activity Commented on by Walter Roberson
on 22 Sep 2017

Hi! I have a bat file created to kill process:

taskkill /IM excel.exe

Can I run it with Matlab?

Thanks

  2 Comments

is there any option of running the .bat file outside the matlab in cmd.exe with matlab commands?

system('nameOfBatFile.bat')

Log in to comment.

Tags

6 Answers

Answer by Walter Roberson
on 27 Jan 2011
 Accepted Answer

You can use system() or dos() or ! (exclamation-mark) to run a bat file.

  0 Comments

Log in to comment.


Answer by Vieniava
on 27 Jan 2011

use this command:

system

Matlab's documentation for this function is available after

>> doc system

or on the WEB

  0 Comments

Log in to comment.


Answer by Jorge
on 27 Jan 2011

I got the result I wanted. Thank you very much to both

  0 Comments

Log in to comment.



thank from me too

  0 Comments

Log in to comment.


Answer by Victor Villar on 3 Jul 2014

Very useful.

Thanks!

  0 Comments

Log in to comment.


Answer by Babak babak on 24 Jul 2017

Hi, guys when I use system or status for my batch file, it does not make outputs like when I double click on my batch file!

>> system('D:\CODE\workshop\MCNP\bab.bat','-echo')
C:\WINDOWS\system32>mcnp i=kc.i  
ans =
    -1.0737e+09

when I double clike on my batch file, it makes for me 3 outputs.

  5 Comments

Well, your file literally named kc.i does not exist in whatever directory the code is running in, which appears to be C:\WINDOWS\system32

I speculate that probably your bab.bat file contains a

   cd C:\WINDOWS\system32
   mcnp i=kc.i

think that is the way to access the program mcnp on input kc.i . Probably your code should instead have something like

   "C:\WINDOWS\system32\mcnp" i=kc.i

without the cd . If you do that then the program should, I think, look in the current directory that MATLAB has set in order to find kc.i

thank you again. I really try to solve it but unfortunately, I couldn't. I have copies 0f Mcnp, bab.bat and kc.i files in Matlab root, D:\CODE\workshop\MCNP\bab.bat and in C:\WINDOWS\system32 but it does not work. My batch file:

   mcnp i=kc.i

and I use this code for my batch file too

    mcnp i=kc.i
     "C:\WINDOWS\system32\mcnp" i=kc.i

the answer:

>> [status, result] = system('C:\Windows\System32\bab.bat')
status =
       0
result =
      '
       C:\WINDOWS\system32>mcnp i=kc.i 
        mcnp    ver=2.6.0 ld=Wed Apr 09 08:00:00 MST 2008   07/25/17 01:36:59
        bad trouble in mcnp    in routine exemes
         input file kc.i does not exist.            
why Matlab try to run it in "WINDOWS\system32"?

Your bat file has a cd in it

Log in to comment.


Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today