0

I have searched about this topic but I can not find a solution. There are some libraries oc2py and pytave However, I am newbie about this. I have a batch file, I want to run it from python:

set SCRIPTS_DIR=(path of neccassary *.m files)

set OCTAVE_COMMAND="cd(getenv('SCRIPTS_DIR')); 
set OCTAVE_COMMAND=%OCTAVE_COMMAND%CORE_LEVEL_PREPROCESS;
set OCTAVE_COMMAND=%OCTAVE_COMMAND%STARTUP_HYDROLOGY_MODULE;
set OCTAVE_COMMAND=%OCTAVE_COMMAND%CORE_LEVEL_OUTPUT_MANAGER;"

start octave-cli.exe --eval %OCTAVE_COMMAND%

CORE_LEVEL_PREPROCESS, STARTUP_HYDROLOGY_MODULE, CORE_LEVEL_OUTPUT_MANAGER are names of *.m files in SCRIPTS_DIR.

I guess I should give that line start octave-cli.exe --eval %OCTAVE_COMMAND% to python but I can not do that.

Mustafa Uçar
  • 442
  • 1
  • 6
  • 18
  • You're not being very clear what you want to do exactly, but here's some links to other questions where I answered about how to use oct2py for particular cases. Hope it helps. https://stackoverflow.com/a/38543580/4183191 https://stackoverflow.com/a/45526673/4183191 https://stackoverflow.com/a/38547151/4183191 https://stackoverflow.com/a/39387123/4183191 – Tasos Papastylianou Aug 31 '18 at 13:29

1 Answers1

0

If this is a batch file, then try:

import os
os.system("D:\\xxx1\\xxx2XMLnew\\otr.bat ")

Failing that, this thread suggests

from subprocess import Popen
p = Popen("batch.bat", cwd=r"C:\Path\to\batchfolder")
stdout, stderr = p.communicate()
Josh Friedlander
  • 10,870
  • 5
  • 35
  • 75