Process Control¶
Process launching and querying
- class mhi.common.process.MIB_TCPROW_LH¶
- class mhi.common.process.MIB_TCPROW_OWNER_PID¶
- mhi.common.process.process_pids(*names: str) List[Tuple[str, int]]¶
Return the process id’s of any process with the given executable names.
Application names may include the
%wildcard. For example, the following query might find bothSkypeApp.exeandSkypeBackgroundHost.exe:process_ids('skype%.exe')
Since applications may terminate and can be started at any time, the returned value is obsolete immediately upon being returned.
- Parameters:
*names (str) – application filename patterns, without any path.
- Returns:
A list of process name & process id pairs
- Return type:
List[tuple]
- mhi.common.process.is_running(app_name: str) bool¶
Determine if there is an
appprocess in the list of running processes.Application names may include the
%wildcard. For example, the following query might find bothSkypeApp.exeandSkypeBackgroundHost.exe:is_running('skype%.exe')
Since applications may terminate and can be started at any time, the returned value is obsolete immediately upon being returned.
- Parameters:
app (str) – application filename, without any path.
- Returns:
True if a process can be found, False otherwise.
- Return type:
bool
- mhi.common.process.tcp_ports_in_use() Set[int]¶
Find all TCP ports in use
- Returns:
Set of all ports in use by the TCP protocol
- Return type:
Set[int]
- mhi.common.process.unused_tcp_port() int¶
Find an available TCP ports in the dynamic/private range
- Returns:
an available TCP port
- Return type:
int
- mhi.common.process.listener_ports_by_pid(*pid: int) List[Tuple[str, int, int]]¶
Find all listener ports opened by processes with the given PIDs.
Since applications may terminate and can be started at any time, as well as open and close ports at any time, the returned value is obsolete immediately upon being returned.
- Parameters:
*pid (int) – Process ids
- Returns:
a list of (addr, port, pid) tuples
- Return type:
List[tuple]
- mhi.common.process.listener_ports_by_name(*names: str) List[Tuple[str, int, int, str]]¶
Find all listener ports opened by processes with the given executable name.
Application names may include the
%wildcard. For example, the following query might find both listener ports opened by bothSkypeApp.exeandSkypeBackgroundHost.exe:listener_ports_by_name('skype%.exe')
Since applications may terminate and can be started at any time, as well as open and close ports at any time, the returned value is obsolete immediately upon being returned.
- Parameters:
*names (str) – application filename patterns, without any path.
- Returns:
a list of (addr, port, pid, name) tuples
- Return type:
List[tuple]
- mhi.common.process.versions(app_name: str) List[Tuple[str, bool]]¶
Find the installed versions of an MHI application.
- Returns:
List of tuples of version and bit-size
- Return type:
List[Tuple]
- mhi.common.process.find_exe(app_name: str, version: Optional[str] = None, x64: Optional[bool] = None, minimum: Optional[str] = None, maximum: Optional[str] = None, allow_alpha: bool = True, allow_beta: bool = True) Optional[str]¶
Find an MHI application executable.
If no
versionis specified, the highest version available is used, with Alpha and Beta versions being considered the highest and second highest respectively. If nox64flag is given, a 32-bit or 64-bit version may be returned, with preference given to 64-bit versions.- Parameters:
app (str) – name of the application (without any extension)
version (str) – application version number such as ‘4.6.3’ or ‘Alpha’
x64 (bool) –
Truefor 64-bit version,Falsefor 32-bit versionminimum (str) – The lowest allowable version, such as ‘5.0’
maximum (str) – The highest allowable version, such as ‘4.6.9’
allow_alpha (bool) – Set to False to exclude alpha versions
allow_beta (bool) – Set to False to exclude beta versions
- Returns:
the path to the executable
- Return type:
str
New in version 2.1:
minimum,maximum,allow_alpha&allow_betaparameters.
- mhi.common.process.launch(*args: str, options: Dict[str, Any] = None, **kwargs)¶
Launch an application process.
All
{keyword}format codes in the list ofargsstrings are replaced by the value in the correspondingoptionsdictionary and/orkwargskey-value argument pairs.For example:
launch("C:\{dir}\{name}.exe", "/silent:{silent}", "/title:{title!r}", dir="temp", name="app", silent=True, title="Hello world")
will launch
C:\temp\app.exepassing the arguments/silent:Trueand/title:'Hello world'- Parameters:
*args (str) – the application and the arguments for the application
options – values which may be substituted in the application arguments
**kwargs – additional substitution values
- Returns:
The subprocess handle
Special keyword arguments¶ Keyword=Value
Effect
minimize=Trueprocess started with
SW_SHOWMINNOACTIVEminimize=Falseprocess started with
SW_SHOWNOACTIVATEdebug=Trueprocess is not started, command line printed