You can use the subprocess
module in Python to run an external .exe
file and provide input to it. Here’s a simple example:
import subprocess # Path to your .exe file exe_path = 'path/to/your/program.exe' # String to be provided as input input_string = 'Your input string here' # Run the .exe file and provide input try: # Use subprocess.run for Python 3.5 and newer result = subprocess.run([exe_path], input=input_string.encode(), text=True, capture_output=True, check=True) # Access the output of the program if needed output = result.stdout print("Program output:", output) except subprocess.CalledProcessError as e: # Handle errors, if any print(f"Error: {e}")
Explanation:
subprocess.run
: Executes the specified command.input
: Specifies the input to be provided to the process. In this example,input_string.encode()
converts the string to bytes, which is the expected input format.text=True
: Treats the input and output as text.capture_output=True
: Captures the standard output of the subprocess.check=True
: Raises asubprocess.CalledProcessError
if the subprocess returns a non-zero exit code, allowing you to handle errors.
Adjust the exe_path
variable to the actual path of your .exe
file and modify the input_string
accordingly. Note that this example assumes the external program reads input from the standard input stream (stdin
). If the program expects input in a different way, you may need to adjust the code accordingly.
Модные советы по подбору превосходных образов на любой день.
Мнения стилистов, события, все новинки и мероприятия.
https://bitwatch.ru/horlogerie/560-novye-modeli-elitnyh-chasov-i-ih-osobennosti/