Mohamad Dabdoub
Mohamad Dabdoub

Reputation: 25

DOS command in MATLAB

I want to ask about a command in Python that performs exactly like the dos() command in MATLAB. For instance, I have the following code block in MATLAB and I want to do exactly the same in Python.

**DIANA = '"C:\Program Files\Diana 10.3\\bin\\DianaIE.exe"'; 
MODEL = 'Input.dcp'; 
INPUTDIR = 'C:\Users\pc\Desktop\Thesis\PSO\'; 
OUTPUTDIR = 'C:\Users\pc\Desktop\Thesis\PSO\'; 
OUTPUT = 'FILE_OUTPUT.out'; 
WORKDIRINPUT = sprintf('%s%s',INPUTDIR,MODEL);
WORKDIROUTPUT = sprintf('%s%s',OUTPUTDIR,OUTPUT);
%
NAMES = sprintf('%s  %s  %s',DIANA,WORKDIRINPUT,WORKDIROUTPUT);
disp('Start DIANA');
dos(NAMES);
disp('End DIANA');**

Upvotes: 1

Views: 193

Answers (2)

Mohamad Dabdoub
Mohamad Dabdoub

Reputation: 25

import subprocess

subprocess.call(['C:\Program Files\Diana 10.3\bin\DianaIE.exe', 'C:\Users\pc\Desktop\Thesis\PSO\Input.py'])

Upvotes: 0

Anto Pravin
Anto Pravin

Reputation: 378

To execute a block of code and get the output in python inside the code you can use a function called exec() and pass the expression or the code to be executed as a string.

This accepts the code as a string. Example..

code = 'x=100\nprint(x)'
exec(code)

Output:

100

And if you want to use the command prompt or power shell commands in python you should you a library named os in python

import os
os.system('cd document')

you can use os.path module for manipulation path and a lot more to know more about this go through this documentation OS-Documentation

Upvotes: 1

Related Questions