i will like a button on my GUI when clicked on, to run and exe file in folder on my computer. Please can anyone help me with possible codes to use so my button can perform this task?

 채택된 답변

Walter Roberson
Walter Roberson 2018년 6월 6일
편집: Walter Roberson 2018년 6월 6일

0 개 추천

function pushbutton1_Callback(hObject, event, handles)
filedir = pwd;
exedir = pwd; %not necessarily the same as where files are
exename = 'gusprime.exe';
exefullname = fullfile(exedir, exename);
fileinfo = dir(fullfile(filedir, '*.dat'));
filenames = fullfile(filedir, {fileinfo.name});
numfiles = length(filenames);
for K = 1 : numfiles
thisfile = filenames{K};
cmd = sprintf('"%s" /some /options /here "%s"', exefullname, thisfile);
[status, message] = system(cmd);
if status == 0
fprintf('Okay processing file "%s"\n', thisfile);
else
fprintf('Error processing file "%s", message was "%s"\n', thisfile, message);
end
end

댓글 수: 4

GUSTAF NJEI
GUSTAF NJEI 2018년 6월 7일
Thanks for your respond but im a little new to matlab so im not sure of the changes i have to make on your codes to fit mine. The only thing i change so far is the line exename = 'gusprime.exe'; to exename = 'pfMainL.exe'; since my exe file name is pfMainL.
Actually that could already be enough, though you maybe do not want a loop. If you only want to run your .exe you need only a few lines of Walters Code.
function pushbutton1_Callback(hObject, event, handles)
exedir = pwd; %pwd gets your current directory, if needed replace with 'C:\Users\....wherever your .exe is
exename = 'pfMainL.exe';
exefullname = fullfile(exedir, exename);
[status, message] = system(exefullname);
end
GUSTAF NJEI
GUSTAF NJEI 2018년 6월 7일
Thanks Denis, that was very helpful but i realized my gui button only runs this exe file when the exe file's folder is open on the current folder pannel. My next question is, how can i set my gui button to always run this exe file no matter if its the exe file's folder open in the current folder pannel or Not.
Walter Roberson
Walter Roberson 2018년 6월 7일
What does it mean for the exe file's folder to be open to something? Are you trying to connect to and run a program that is already running?
When you run pfMainL for a particular file, what would you type on the command line if you were doing it by hand?
I am having difficulty finding pfMainL.exe on the internet to find documentation about it?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 App Building에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by