Try This:
from subprocess import Popen, check_output, check_call, PIPE, call
get_input = input("What Should I do?")
if get_input.strip().lower() == "run":
your_exe_file_address = r'"C:\Users\you\Desktop\my_file.exe"' # example
your_module_address = r'"C:\Users\you\Desktop\test.m"' # example
your_command = "call"
process = Popen([your_exe_file_address, your_command, your_module_address], stdout=PIPE, stderr=PIPE, shell=True)
stdout, stderr = process.communicate()
# < Other Ways >
# process = check_output([your_exe_file_address, your_command, your_module_address])
# process = check_call([your_exe_file_address, your_command, your_module_address], shell=True)
# process = call([your_exe_file_address, your_command, your_module_address], stdout=PIPE, stderr=PIPE, shell=True)
print(stdout, stderr)
else:
print("Invalid Input")
Another Way :
import os
get_input = input("What Should I do?")
if get_input.strip().lower() == "run":
your_exe_file_address = r'"C:\Users\you\Desktop\my_file.exe"' # example
your_module_address = r'"C:\Users\you\Desktop\test.m"' # example
your_command = "call"
last_shell = your_exe_file_address + " " + your_command + " " + your_module_address
os.system(last_shell)
else:
print("Invalid Input")
Third Way ( On Windows, install pywin32 package ):
import win32com.client
get_input = input("What Should I do?")
if get_input.strip().lower() == "run":
your_exe_file_address = r'"C:\Users\you\Desktop\my_file.exe"' # example
your_module_address = r'"C:\Users\you\Desktop\test.m"' # example
your_command = "call"
last_shell = your_exe_file_address + " " + your_command + " " + your_module_address
shell = win32com.client.Dispatch("WScript.Shell")
shell.Run(last_shell)
else:
print("Invalid Input")
Fourth way :
Save your commands in a .bat file like this:
"C:\Users\you\Desktop\my_file.exe" call "C:\Users\you\Desktop\test.m"
Then try to launch this bat file and get its output:
import os
get_input = input("What Should I do?")
if get_input.strip().lower() == "run":
your_bat_file_address = r'"C:\Users\you\Desktop\my_bat.bat"' # example
os.startfile(your_bat_file_address)
else:
print("Invalid Input")
Good Luck ...