Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # bashfulpy.py
- import subprocess
- import json
- import tempfile
- import os
- arg1 = 2
- arg2 = 4
- arg3 = 6
- arg4 = 8
- # Create a Bash script to perform the calculations and output the result as JSON
- script = f'''
- @echo off
- set /a arg1_result={arg1} * 9
- set /a arg2_result={arg2} * 9
- set /a arg3_result={arg3} * 9
- set /a arg4_result={arg4} * 9
- echo (%arg1_result%, %arg2_result%, %arg3_result%, %arg4_result%)
- '''
- # Create a temporary file to save the script
- with tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.bat') as script_file:
- script_file.write(script)
- script_file_name = script_file.name
- # Call the script using cmd.exe to perform the calculations and obtain the result as bytes
- result_bytes = subprocess.check_output(['cmd.exe', '/C', script_file_name], shell=True)
- # Decode the result bytes into a string
- result_string = eval(result_bytes.decode().strip())
- print("Received result:", [result_string])
- # Clean up the temporary script file
- os.remove(script_file_name)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement