Open .exe file through .bat file in Flask
Question: I am trying to open an .exe file (e.g. Paint) with a html button using Flask,
so I wrote a small .bat file that runs it properly when I run it through
Python, but does not seem to work when I open it through Flask.

The Python is:

    
    
    @app.route('/assemblies', methods=['GET', 'POST'])
    def assemblies():
        if request.method == 'POST':
            if request.form['submit'] == 'runFile':
                #os.startfile("/static/run.bat")
                text = "... running ..."
                filepath="/static/run.bat"
                p = subprocess.Popen(filepath, shell=True, stdout = subprocess.PIPE)
                stdout, stderr = p.communicate()
                return render_template('assemblies.html', text=text)
            else request.form['submit'] == 'process':
                [do other stuff]
        elif request.method == 'GET':
            return render_template('assemblies.html')
    

(Part of) the html file is:

    
    
    <div class="container">
        <form action="/assemblies" method="post"> ASSEMBLY <br> 
            <select name="Layer">
                <option value="1">1</option>        
                <option value="2">2</option>
                <option value="3">3</option>
                <option value="4">4</option>
                <option value="5">5</option>
            </select><br>
            <button type="submit" name="submit" value="process"> Process </button>
            <button  type="submit" name="submit" value="runFile"> Run </button> 
        </form>
    </div>
    

And the bat is:

    
    
    start /d "static\" myFile.exe
    

The bat file works outside Flask, but I have tried with the exe and bat both
in the 'static' folder and on C:/ and seems to be completely unresponsive (no
console feedback), so I assume I might be missing something important?


Answer: Found a solution after changing:

    
    
    filepath="/static/run.bat"
    p = subprocess.Popen(filepath, shell=True, stdout = subprocess.PIPE)
    stdout,  = p.communicate()
    

for:

    
    
    subprocess.call(["static/myFile.exe"])
    

and now it works. I am bypassing the bat file, but not sure what was the
problem with the original script, so any insights are still welcome.

