Filter löschen
Filter löschen

Can I run a bat file with Matlab?

238 Ansichten (letzte 30 Tage)
Jorge
Jorge am 27 Jan. 2011
Kommentiert: Waldemar Gessler am 12 Nov. 2019
Hi! I have a bat file created to kill process:
taskkill /IM excel.exe
Can I run it with Matlab?
Thanks
  3 Kommentare
Walter Roberson
Walter Roberson am 22 Sep. 2017
system('nameOfBatFile.bat')
Waldemar Gessler
Waldemar Gessler am 12 Nov. 2019
or without bat file:
system('taskkill /IM excel.exe')

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 27 Jan. 2011
You can use system() or dos() or ! (exclamation-mark) to run a bat file.

Weitere Antworten (5)

Vieniava
Vieniava am 27 Jan. 2011
use this command:
system
Matlab's documentation for this function is available after
>> doc system
or on the WEB

Jorge
Jorge am 27 Jan. 2011
I got the result I wanted. Thank you very much to both

Koteswar Rao  Jerripothula
Koteswar Rao Jerripothula am 31 Jan. 2014
thank from me too

Victor Villar
Victor Villar am 3 Jul. 2014
Very useful.
Thanks!

Babak babak
Babak babak am 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 Kommentare
Babak babak
Babak babak am 24 Jul. 2017
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"?
Walter Roberson
Walter Roberson am 24 Jul. 2017
Your bat file has a cd in it

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by