Search code examples
python-2.7cmdcommand-promptexternalexecutable

Entering a command to an opened Command Prompt window with python script


I have been trying enter couple of commands on a command window with python script. I was able to open the .exe file by checking the other questions.

However, now my code:

import os
os.chdir(r'filepath')
os.system("start /B start filepath\application.exe")

opens the application and it asks for an input file name, then it will ask for output file name. Is there a way to do that. This will be used for ArcGIS so it needs to be done in python 2.7.

I checked all related questions but did not find the answer. I would appreciate it very much if you could help.


Solution

  • Finally! It was easier than I thought but I needed lots of research. This code for python 2.7 which may differ for other versions.

    import os
    import subprocess
    os.chdir(r'filepath')
    subprocess.check_call([r"filepath\your_.exe_app", 'your_input'])