[Network security takes you to practice reptiles-100 exercises] Practice 19: Use python to open exe files

Table of contents

1. Goal 1: Call the exe file

2. Goal 2: Call exe to open the file


1. Goal 1: Call the exe file

1. The subprocess module allows starting a new process in Python and interacting with it

2. The subprocess.run() function to start the exe file

3. subprocess.run(["file path"], check=True/)

4. check: If the program returns a non-zero exit code, the subprocess.run() function will throw a CalledProcessError exception

import subprocess

# 启动 notepad.exe 程序,并等待程序运行结束后再继续执行 Python 代码
subprocess.run(["D:\\渗透工具\\010\\010Editor.exe"], check=True)

Note:

1. Python will try to convert the escape sequence similar to \Uxxxxxxxx in the string to the corresponding Unicode character

2. In Python, the backslash \ is used to represent the escape character, such as \n represents a newline character, and \t represents a tab character. Here to use the backslash \ character itself in the string, you need to use double backslashes \\ to represent



2. Goal 2: Call exe to open the file

1. First specify the filename to open.

2. Use the subprocess.run() function to start the exe program, and pass the file name to the program as a parameter

3. After the exe program starts, it will try to open the specified file

import subprocess

filename = "D:\\1.png"

# 启动 exe 程序,并将文件名作为参数传递给程序
subprocess.run(["D:\\渗透工具\\010\\010Editor.exe", filename])

Guess you like

Origin blog.csdn.net/qq_53079406/article/details/132100383