Can I run a bat file with Matlab?

Hi! I have a bat file created to kill process:
taskkill /IM excel.exe
Can I run it with Matlab?
Thanks

3 件のコメント

Sanket
Sanket 2017 年 9 月 22 日
is there any option of running the .bat file outside the matlab in cmd.exe with matlab commands?
Walter Roberson
Walter Roberson 2017 年 9 月 22 日
system('nameOfBatFile.bat')
Waldemar Gessler
Waldemar Gessler 2019 年 11 月 12 日
or without bat file:
system('taskkill /IM excel.exe')

サインインしてコメントする。

 採用された回答

Walter Roberson
Walter Roberson 2011 年 1 月 27 日

5 投票

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

1 件のコメント

Nagendra
Nagendra 2024 年 8 月 22 日
編集済み: Nagendra 2024 年 8 月 22 日
Perfect, thank you

サインインしてコメントする。

その他の回答 (6 件)

Vieniava
Vieniava 2011 年 1 月 27 日

2 投票

use this command:
system
Matlab's documentation for this function is available after
>> doc system
or on the WEB
Jorge
Jorge 2011 年 1 月 27 日

0 投票

I got the result I wanted. Thank you very much to both
Koteswar Rao Jerripothula
Koteswar Rao Jerripothula 2014 年 1 月 31 日

0 投票

thank from me too
Victor Villar
Victor Villar 2014 年 7 月 3 日

0 投票

Very useful.
Thanks!
Babak babak
Babak babak 2017 年 7 月 24 日

0 投票

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 件のコメント

Walter Roberson
Walter Roberson 2017 年 7 月 24 日
[status, result] = system('D:\CODE\workshop\MCNP\bab.bat','-echo');
Now look at result
Babak babak
Babak babak 2017 年 7 月 24 日
編集済み: Babak babak 2017 年 7 月 24 日
Thank you very much for your kind attention. It looks better but I don't know why it can't find the input! I copy my input in the Matlab root too. Should I copy them in the other place?
It's the answer:
[status, result] = system('D:\CODE\workshop\MCNP\bab.bat','-echo');
C:\WINDOWS\system32>mcnp i=kc.i
mcnp ver=2.6.0 ld=Wed Apr 09 08:00:00 MST 2008 07/24/17 22:32:16
bad trouble in mcnp in routine exemes
input file kc.i does not exist.
Walter Roberson
Walter Roberson 2017 年 7 月 24 日
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
Babak babak
Babak babak 2017 年 7 月 24 日
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 2017 年 7 月 24 日
Your bat file has a cd in it

サインインしてコメントする。

dilek dua
dilek dua 2025 年 4 月 30 日

0 投票

% Parametreler q1 = 120; % mm^3/s q2 = 40; % mm^3/s q3 = 80; % mm^3/s

D1 = 10; % mm D2 = 10; % mm h1 = 50; % mm h2 = 20; % mm

A1 = (pi * D1^2) / 4; % mm^2 A2 = (pi * D2^2) / 4; % mm^2

V1 = A1 * (h1 + h2); % Büyük kabın toplam hacmi V2 = A2 * h1; % Küçük kabın hacmi

% Simülasyon ayarları dt = 1; % zaman adımı (s) max_time = 200; % maksimum süre time = 0:dt:max_time;

% Başlangıç değerleri V_buyuk = 0; V_kucuk = 0; h_buyuk = 0; h_kucuk = 0;

% Kayıt için vektörler h_buyuk_vec = zeros(size(time)); h_kucuk_vec = zeros(size(time));

% Simülasyon for i = 1:length(time)

    if h_buyuk < h1
        V_buyuk = V_buyuk + q1 * dt;
    else
        V_buyuk = V_buyuk + (q1 - q2) * dt;
        V_kucuk = V_kucuk + q2 * dt;
    end
    % Küçük kaptan taşma
    if h_kucuk >= h1
        V_kucuk = V_kucuk - q3 * dt;
        if V_kucuk < 0
            V_kucuk = 0;
        end
    end
    % Yükseklik hesaplama
    h_buyuk = min(V_buyuk / A1, h1 + h2);
    h_kucuk = min(V_kucuk / A2, h1);
    h_buyuk_vec(i) = h_buyuk;
    h_kucuk_vec(i) = h_kucuk;
    % Büyük kap tamamen dolunca çık
    if h_buyuk >= (h1 + h2)
        h_buyuk_vec(i+1:end) = h_buyuk;
        h_kucuk_vec(i+1:end) = h_kucuk;
        break;
    end
end

% Grafik çizimi plot(time, h_buyuk_vec, 'r', 'LineWidth', 2) hold on plot(time, h_kucuk_vec, 'b', 'LineWidth', 2) xlabel('Zaman (s)') ylabel('Su Yüksekliği (mm)') legend('Büyük Kap', 'Küçük Kap') title('Zaman - Su Yüksekliği Grafiği') grid on

カテゴリ

ヘルプ センター および File ExchangeScope Variables and Generate Names についてさらに検索

タグ

質問済み:

2011 年 1 月 27 日

編集済み:

2024 年 8 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by