Three methods of calling executable file. exe in python
- 2021-07-10 20:17:53
- OfStack
Method 1.
os. system () saves the print value in the executable and the return value of the main function, and prints out what is to be printed during execution
import os
main = "project1.exe"
r_v = os.system(main)
print (r_v )
Method 2.
commands. getstatusoutput () saves the printed value in the executable and the return value of the main function, but does not print out what is to be printed during execution
import subprocess
import os
main = "project1.exe"
if os.path.exists(main):
rc,out= subprocess.getstatusoutput(main)
print (rc)
print ('*'*10)
print (out)
Method 3.
popen () saves the printed value in the executable program, but does not save the return value of the main function, nor does it print out what is to be printed during execution
import os
main = "project1.exe"
f = os.popen(main)
data = f.readlines()
f.close()
print (data)
In addition, the three methods mentioned above are actually executing commands in python, so they are not only used to execute executable files, but also can be used to execute other instructions in linux system.