I'm using eg.plugins.System.Execute in a python script to perform some dos command (schtasks.exe /query - to get a list of running tasks). Now, I want to take the result of that command and parse it. How do I get an output from System.Execute and save it in a python variable? Any creative way of doing it?
I thought of doing " > temp.tmp" at the end to save the output to a file, I guess it's a possibility, just looking for a more elegant way of doing it, if it's possible.
Thanks.
Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details
If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.
If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.
Get result from System.Execute
- Pako
- Plugin Developer
- Posts: 2294
- Joined: Sat Nov 11, 2006 1:31 pm
- Location: Czech Republic
- Contact:
Re: Get result from System.Execute
I think that you can not use the normal eg.plugins.System.Execute action.
It will be necessary to use the Python Script action.
For example, the following:
It is obviously not necessary to use eg.result.
Pako
It will be necessary to use the Python Script action.
For example, the following:
Code: Select all
eg.result = None
from subprocess import Popen, PIPE, STDOUT, SW_HIDE
def popen(cmd):
proc = Popen(cmd.split(),stdout = PIPE,stderr = STDOUT,creationflags = SW_HIDE, shell = True)
data = proc.communicate()[0]
return (proc.returncode, data)
ret, data = popen("call chcp") #DOS console codepage
if not ret:
cp = "cp" + data.split()[-1]
ret, data = popen("schtasks.exe /query")
if not ret:
eg.result = data.decode(cp)Pako