runService

语法

System.runService( , , [option] )

类别

System

描述

运行service命令

参数

参数名参数类型默认值描述是否必填
servicenamestring—-服务名
commandstring—-运行服务名对应的命令
optionstring运行命令的选项

返回值

返回运行service命令的信息

错误

如果出错则抛异常,并输出错误信息,可以通过getLastErrMsg()获取错误信息或通过getLastError()获取错误码。 关于错误处理可以参考常见错误处理指南

常见错误可参考错误码

示例

  • 查看ssh服务信息

    1. > System.runService( "ssh", "status", "" )
    2. ssh.service - OpenBSD Secure Shell server
    3. Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
    4. Active: active (running) since 2019-05-29 10:29:47 CST; 6 days ago
    5. Main PID: 1637 (sshd)
    6. Tasks: 1
    7. Memory: 5.6M
    8. CPU: 1.268s
    9. CGroup: /system.slice/ssh.service
    10. └─1637 /usr/sbin/sshd -D
    11. 6 04 14:57:06 hostname sshd[24292]: pam_unix(sshd:session): session opened for user sdbadmin by (uid=0)
    12. 6 04 15:12:22 hostname sshd[17900]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=192.168.10.124 user=username