Python API¶
OperatingSystem¶
-
class
RPA.Desktop.OperatingSystem.
OperatingSystem
¶ Bases:
object
OperatingSystem is a cross-platform library for managing computer properties and actions.
Examples
Robot Framework
*** Settings *** Library RPA.Desktop.OperatingSystem *** Tasks *** Get computer information ${boot_time}= Get Boot Time as_datetime=${TRUE} ${machine}= Get Machine Name ${username}= Get Username &{memory}= Get Memory Stats Log Many ${memory}
Python
from RPA.Desktop.OperatingSystem import OperatingSystem def get_computer_information(): ops = OperatingSystem() print(f"Boot time : { ops.get_boot_time(as_datetime=True) }" f"Machine name : { ops.get_machine_name() }" f"Username : { ops.get_username() }" f"Memory : { ops.get_memory_stats() }") if __name__ == "__main__": get_computer_information()
-
ROBOT_LIBRARY_DOC_FORMAT
= 'REST'¶
-
ROBOT_LIBRARY_SCOPE
= 'GLOBAL'¶
-
boot_time_in_seconds_from_epoch
() → str¶ Get machine boot time
- Returns
boot time in seconds from Epoch
Example:
${epoch} Boot Time In Seconds From Epoch
-
get_boot_time
(as_datetime: bool = False, datetime_format: str = '%Y-%m-%d %H:%M:%S') → str¶ Get computer boot time in seconds from Epoch or in datetime string.
- Parameters
as_datetime – if True returns datetime string, otherwise seconds, defaults to False
datetime_format – datetime string format, defaults to “%Y-%m-%d %H:%M:%S”
- Returns
seconds from Epoch or datetime string
Example:
${boottime} Get Boot Time ${boottime} Get Boot Time as_datetime=True ${boottime} Get Boot Time as_datetime=True datetime_format=%d.%m.%Y
-
get_machine_name
() → str¶ Get machine name
- Returns
machine name as string
Example:
${machine} Get Machine Name
-
get_memory_stats
(humanized: bool = True) → dict¶ Get computer memory stats and return those in bytes or in humanized memory format.
- Parameters
humanized – if False returns memory information in bytes, defaults to True
- Returns
memory information in dictionary format
Example:
&{mem} Get Memory Stats &{mem} Get Memory Stats humanized=False
-
get_username
() → str¶ Get username of logged in user
- Returns
username as string
Example:
${user} Get Username
-
kill_process
(process_name: str) → bool¶ Kill process by name
- Parameters
process_name – name of the process
- Returns
True if succeeds False if not
Example:
${process} Process Exists calc strict=False ${status} Kill Process ${process.name()}
-
kill_process_by_pid
(pid: int) → None¶ Kill process by pid
- Parameters
pid – process identifier
Example:
${process} Process Exists calc strict=False ${status} Kill Process By PID ${process.pid}
-
process_exists
(process_name: str, strict: bool = True) → Any¶ Check if process exists by its name
- Parameters
process_name – search for this process
strict – defines how match is made, default True which means that process name needs to be exact match and False does inclusive matching
- Returns
process instance or False
Example:
${process} Process Exists calc ${process} Process Exists calc strict=False
-
process_id_exists
(pid: int) → Any¶ Check if process exists by its id
- Parameters
pid – process identifier
- Returns
process instance or False
Example:
${process} Process ID Exists 4567 Run Keyword If ${process} Log Process exists
-
put_system_to_sleep
() → None¶ Puts system to sleep mode
Example:
Put System To Sleep
-