gahhon Posted February 16, 2019 Posted February 16, 2019 I have a python script automate.py and I wanna run it via CMD. As I know to execute python via CMD is something like this $CMD = "Something python here" Run(@ComSpec & " /c " & $CMD) But how can I just open the 1 CMD and send multiple commands to the CMD based on the function called? For instance like: Launch CMD and send python then send import automate If google() function is called - send automate.google() to the CMD If yahoo() function is called - send automate.yahoo() to the CMD I don't want to execute multiple CMD to call the automate functions. This is due to inside the python script have global variable to handle duplicate flag. So if I execute multiple CMD to call the functions, the global variable will be keep new as NULL. Which is not my expectation. Thanks
Nine Posted February 16, 2019 Posted February 16, 2019 you could use STDIO to communicate with Python. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
gahhon Posted February 16, 2019 Author Posted February 16, 2019 6 minutes ago, Nine said: you could use STDIO to communicate with Python. Any sample of it? I couldn't find any relevant topic in google search
Nine Posted February 16, 2019 Posted February 16, 2019 33 minutes ago, gahhon said: Any sample of it? Not specifically to python, but the more general approach with StdinWrite, StdOutRead, Run (), you should find tons of examples “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
gahhon Posted February 16, 2019 Author Posted February 16, 2019 (edited) 1 hour ago, Nine said: Not specifically to python, but the more general approach with StdinWrite, StdOutRead, Run (), you should find tons of examples Anyway, I cannot work with the method of StdinWrite, StdOutRead and Run(). It just open empty CMD without trigger anything tho. But somehow I found this method send hidden command text and it work perfectly as expect as well as found some source how to hide CMD window with WinWait. Finally my sample code: Global $handle, $iFlag = False Func CMDSetup() Run(@ComSpec & " /k TITLE HideCmd","",@SW_HIDE) $handle = (WinWait("HideCmd", "", 3) ? (WinActivate("[LAST]") ? WinWaitActive("[LAST]") : 0) : SetError(1, 0, 0)) ControlSend($handle, "", "", "python" & @CRLF) ControlSend($handle, "", "", "import automate;" & @CRLF) $iFlag = True EndFunc Func Google() If $iFlag = False Then CMDSetup() ControlSend($handle, "", "", "automate.google()" & @CRLF) EndFunc Func Yahoo() If $iFlag = False Then CMDSetup() ControlSend($handle, "", "", "automate.yahoo()" & @CRLF) EndFunc Thanks. Edited February 16, 2019 by gahhon Successful to achieve result
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now