![]() |
Equivalent Python code from VBA - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Equivalent Python code from VBA (/thread-40291.html) |
Equivalent Python code from VBA - Mishal0488 - Jul-05-2023 Hi Guys Refer to the below code which is developed on Excel VBA, the code essentially opens Space Gass and passes the text to the Space Gass. What would the equivalent be on Python? I currently have managed to open Space Gass from Python using "subprocess.call()" Dim strSGProgram As String strSGProgram = """" & "C:\Program Files (x86)\SPACE GASS 14\sgwin.exe" & """" Dim strSGScript As String strSGScript = " -s " & """" & "c:\temp\SGScriptDemo\Save and close script.txt" & """" Call Shell(strSGProgram & strSGScript, vbMinimizedNoFocus) RE: Equivalent Python code from VBA - carecavoador - Jul-05-2023 I guess you could do something like this: import subprocess strSGProgram = r'"C:\Program Files (x86)\SPACE GASS 14\sgwin.exe"' strSGScript = r' -s "c:\temp\SGScriptDemo\Save and close script.txt"' command = strSGProgram + strSGScript subprocess.run(command, creationflags=subprocess.CREATE_NO_WINDOW, shell=True)Edit: updated to subprocess.run() since subprocess.call() is deprecated.
RE: Equivalent Python code from VBA - masonsbore - Apr-19-2024 happy wheels Thank you, that resolved it RE: Equivalent Python code from VBA - SamCoffee - Apr-30-2024 half body sexdoll To achieve the equivalent functionality in Python, you can use the subprocess module to call the Space Gass executable and pass the script file as an argument. RE: Equivalent Python code from VBA - DeaD_EyE - May-02-2024 import subprocess from subprocess import CREATE_NO_WINDOW # use better names # use forward slahes to avoid complications with backslashes program = "C:/Program Files (x86)/SPACE GASS 14/sgwin.exe" script = "C:/temp/SGScriptDemo/Save and close script.txt" subprocess.run([program, "-s", script], creationflags=CREATE_NO_WINDOW)Don't use shell=True. By default shell=False. |