title: Sequentially running python programs and matlab files using batch
body: <p>I run by batch</p>
  
  <pre><code>call C:\python27\python.exe program1.py input1 output1
  call C:\python27\python.exe program2.py input2 output2
  </code></pre>
  
  <p>Next, I have to run multiple matlab m-file programs.</p>
  
  <p>Then next, I run batch</p>
  
  <pre><code>call C:\python27\python.exe program3.py input3 output4
  call C:\python27\python.exe program4.py input3 output4
  </code></pre>
  
  <p>Then I run other matlab programs, and so on.</p>
  
  <p>But it will be very convenient if I can run all these both python and matlab m-files by double clicking a single batch file.</p>
  
  <p>If a batch file cannot know when the execution of m-file ends, I came up with a imaginary solution that might be possible.</p>
  
  <p>Since each m-file generates a unique output, "this line of batch file is executed when 2 minutes have passed after matlab_output1.txt is created in the folder that this batch file is in"</p>
  
  <p>I chose "2 minutes" because just the fact that "matlab_output1.txt" is created does not mean the m-file finished creating "matlab_output1.txt",</p>
  
  <p>and perhaps creating one txt file will not take more than 2 minutes for MatLab.</p>
  
  <p>I also tried this.</p>
  
  <pre><code>start "01" /wait "C:\Program Files\MATLAB\R2012a\bin\matlab.exe" mfile.m
  start "02" /wait "C:\python27\python.exe" python.py input.xlsx
  </code></pre>
  
  <p>and</p>
  
  <pre><code>start "01" /wait "C:\Program Files\MATLAB\R2012a\bin\matlab.exe" -r "m-file; exit"
  start "02" /wait "C:\python27\python.exe" python.py input.xlsx
  </code></pre>
  
  <p>But both solutions failed. It started to run python before even matlab program launched.</p>
  
  <p><strong>-wait</strong></p>
  
  <p>moarningsun suggested to add -wait.</p>
  
  <p>So I tried</p>
  
  <pre><code>start "01" /wait "C:\Program Files\MATLAB\R2012a\bin\matlab.exe" -wait -r "aatest; exit;"
  start "02" /wait "C:\python27\python.exe" simple_tool_naming.py match_naming1.xlsx
  </code></pre>
  
  <p>Yes, finally python program doesn't start before matlab does something.</p>
  
  <p>But still the problem is it can't run the mfile.</p>