使用Cygwin监视Windows服务

问题描述 投票:6回答:2

我试图将我的一些常规shell操作从PowerShell转移到Cygwin,主要是作为一种教育练习,但也因为我真的开始喜欢一些Linux风味工具。我还在尝试研究如何列出/操作Windows服务。 PowerShell有一些非常方便的工具,例如:

stop-service [pattern]
start-service [pattern]
gsv (or get-service) [pattern]

我最近使用了很多自定义服务,并且不想在我的常规工作流程中切换到PowerShell来执行此操作。有人解决了这个问题吗?谷歌的一些尝试已被许多关于如何处理作为服务运行的Cygwin的东西所阻碍。

cygwin
2个回答
7
投票

从Cygwin中调用PowerShell命令:

cmd /c '%SystemRoot%\\system32\\WindowsPowerShell\\v1.0\\powershell.exe' -Command "gsv"

更通用的解决方案是创建一个脚本powershell.sh,其中包含:

#!/bin/bash
set -e
set -u
cmd /c '%SystemRoot%\\system32\\WindowsPowerShell\\v1.0\\powershell.exe' -Command "$@"

之后你可以运行:./powershell.sh gsv或你需要的任何命令。


0
投票

从Cygwin中调用PowerShell而不调用CMD.exe。

使用PowerShell 6.x Core的pwsh命令,我们终于将PowerShell作为我们脚本箱中的另一个工具,包括perl,ruby,python等。

当前版本的powershell可以用作shebang而不会出现```#!pwsh`。较旧的Win7版本的PS2与DOS控制台绑定在一起,你必须制作一个包装器并在she-bang系列中调用该包装器。

© www.soinside.com 2019 - 2024. All rights reserved.