Close cmd while getting results

Hello,
I was tring to run an exe from system in matlab and get the result before it gets stuck.
I tried [status,result]= system('name.exe < input.txt &' )and I did not get the results.
I am trying tic toc but it seems that it is not returning to Matlab from exe....
this is the part of the code.
cmd='xfoilP4.exe < xfoilinput.txt';
if toc(timer1)<waiting
[status,results]=system(cmd);
else
!taskkill -f -im xfoilP4.exe;
end

Answers (2)

What is the purpos of:
if toc(timer1)<waiting
This not a loop and it does not wait until your command in the system() call is running. This is evaluated once before the system command is started. If the taskkill command is triggered, the system command did not run before.
What does "get the result before it gets stuck" mean? When the command does not finish, you do not get any results.
Please explain exactly again, what you want to achieve.

1 Comment

Sina Rangriz
Sina Rangriz on 10 Aug 2021
Edited: Sina Rangriz on 10 Aug 2021
Thanks Jan for answering.
Actually I need to get some results from system command and analyze it...
cmd='xfoilP4.exe < xfoilinput.txt';
[status,results]=system(cmd);
the results are saving in results but sometimes it gets stuck in second line and it doesn't return to Matlab....so I want to close the cmd when it happens....
I used timer but it is not working.....
but it is closing by using PID and it is not relevent to me because I want to get the text file which is printed in the cmd and based on that taskkill the cmd...
I cannot change the script of xfoilP4.exe because it is predefined.

Sign in to comment.

Image Analyst
Image Analyst on 10 Aug 2021
Not sure if this is what you want, but if you don't want the CMD window (console window) to show up while you run your .exe, you can use the -e option to mcc when you compile it. It will just show your GUI without the additional console window.

5 Comments

Thanks,
Actually no, the problem is that when I run the code, sometimes based on input that I write in "inputxfoil.txt", this line is getting stuck:[status,results]=system(cmd);
getting stuck means that It is not returning to the Matlab and I want to force close xfoilP4.exe when this happens....I don't want to close the exe file manually from task manager.
I tried timer, but it doesn't work.the code that I wrote in original message is wrong and I am aware of that.
It's supposed to wait until you close the console window. Then when you close it manually, your MATLAB code will resume executing. Is that what happens?
I wonder if you put something like this in your command list, it will shutdown the console window automatically:
system('taskkill /F /IM EXCEL.EXE');
Change it from excel to cmd.exe and see if it goes away.
Sina Rangriz
Sina Rangriz on 10 Aug 2021
Edited: Sina Rangriz on 10 Aug 2021
thank you for answering, yes, exactly, it continues the rest of the code in Matlab.I cannot do this manually, because the exe file is running around 250,000 times. I will try and let you know.Thanks!
btw, can I get the results before it exits?
Try taskkill.
I don't think you can get anything from the console window before it exits since I believe MATLAB is just spinning it's wheels at that point waiting for the process to end. You might have to have your process write something to disk and have MATLAB open that file when it resumes.
Sina Rangriz
Sina Rangriz on 10 Aug 2021
Edited: Sina Rangriz on 10 Aug 2021
UPDATE:
Hello,
I tried using taskkill inside the command list...it is not working

Sign in to comment.

Categories

Products

Release

R2020b

Tags

Asked:

on 9 Aug 2021

Edited:

on 10 Aug 2021

Community Treasure Hunt

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

Start Hunting!