Advertisement
here2share

# bashfulpy.py

Nov 13th, 2023
947
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.01 KB | None | 0 0
  1. # bashfulpy.py
  2.  
  3. import subprocess
  4. import json
  5. import tempfile
  6. import os
  7.  
  8. arg1 = 2
  9. arg2 = 4
  10. arg3 = 6
  11. arg4 = 8
  12.  
  13. # Create a Bash script to perform the calculations and output the result as JSON
  14. script = f'''
  15. @echo off
  16.  
  17. set /a arg1_result={arg1} * 9
  18. set /a arg2_result={arg2} * 9
  19. set /a arg3_result={arg3} * 9
  20. set /a arg4_result={arg4} * 9
  21.  
  22. echo (%arg1_result%, %arg2_result%, %arg3_result%, %arg4_result%)
  23. '''
  24.  
  25. # Create a temporary file to save the script
  26. with tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.bat') as script_file:
  27.     script_file.write(script)
  28.     script_file_name = script_file.name
  29.  
  30. # Call the script using cmd.exe to perform the calculations and obtain the result as bytes
  31. result_bytes = subprocess.check_output(['cmd.exe', '/C', script_file_name], shell=True)
  32.  
  33. # Decode the result bytes into a string
  34. result_string = eval(result_bytes.decode().strip())
  35.  
  36. print("Received result:", [result_string])
  37.  
  38. # Clean up the temporary script file
  39. os.remove(script_file_name)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement