- Open MATLAB with Administrative Privileges and navigate to the directory where your Python script is located.
- In MATLAB, create a new script or open an existing one.
- Use the ‘system’ function to call the Python interpreter with administrative privileges. Consider the sample code below:
Run a python exe from within a Matlab exe with Administrator permissions
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I would like to run a python.exe from within a Matlab.exe file with administrator permissions.Unfortunately, the python.exe does not have the necessary permissions to write out a file. I have tried executing it directly from command prompt as administrator and it works perfectly. The process fails when I try executing it within the matlab exe. The workflow is as follows:
- The python.exe receives two inputs as arguments i) filename - which is a path to a particular file ii) value
ML_correction.exe --filename "C:/.../../xx.txt" --corrected_val "-185.7"
The python exe computes a certain value and writes out a .mat file
2. The above command to call the python exe is executed within a Matlab exe as follows:
python_path="C:/.../../xx.txt";
val=-185.7;
cmd_command=['.\...\ML_correction.exe --filename "' python_path '" --corrected_val "' num2str(val) '"'];
[status,cmdout] = system(cmd_command);
I have read the suggestions from @Jan and @Guillaume : https://de.mathworks.com/matlabcentral/answers/398700-run-external-software-from-matlab-using-system-with-admin-rights
I tried to pass my arguments using ShellExecute from Microsoft documentation but I am definitely doing it wrong. I have tried the following:
cmd_command=['.\...\ML_correction.exe --filename "' python_path '" --corrected_val "' num2str(val) '"'];
exepath=string(cmd_command);
uac = actxserver('Shell.Application');
uac.ShellExecute(exepath, "ELEV", "", "runas", 1);
Thank You!
I am using Windows 10 and Matlab2017b
0 Kommentare
Antworten (1)
arushi
am 23 Aug. 2024
Hi Adithya Kalliath
To execute a Python script in MATLAB with admin privileges, you can utilize the 'system' function within MATLAB. This function allows you to invoke the Python interpreter with administrative rights.
Here are the steps you can follow to accomplish this:
system('python "path_to_your_script.py"')
Replace "path_to_your_script.py" with the actual path of your Python script.
4. Now modify the file extension from '.m' to an executable file .
Now, your Python file will be executed with administrative privileges.
For additional information regarding the ‘system’ function you can refer to the following documentation:
Hope this helps.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Call Python from MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!