启动进程在当前目录中工作,但不使用绝对路径

问题描述 投票:0回答:1

我是 PowerShell 新手,现在有点困惑。

这里有两个例子,在我看来,它们应该以同样的方式工作。但看来我错了。

示例1:

$ Get-Location

Path
----
C:\Users\toto

$ cd .\Dev\nginx-1.22.1\
$ Start-Process .\nginx.exe
$ Get-Process -Name nginx

 NPM(K)    PM(M)      WS(M)     CPU(s)      Id  SI ProcessName
 ------    -----      -----     ------      --  -- -----------
 11     1,86       9,25       0,00    8824   5 nginx
 13     2,37       9,56       0,00   30068   5 nginx

所以一切看起来都很好。

示例2:

$ Get-Location

Path
----
C:\Users\toto

$ Start-Process -FilePath C:\Users\toto\Dev\nginx-1.22.1\nginx.exe
$ Get-Process -Name nginx

Get-Process: Cannot find a process with the name "nginx". Verify the process name and call the cmdlet again.

所以,基本上,在第一个示例中,我首先转到 .exe 文件位置并启动它。在第二个示例中,我使用 .exe 文件的绝对路径,但它不起作用。正常吗?我想我错过了一些关于

Start-Process
或其他东西的使用。如果有任何帮助,我将不胜感激。

powershell path exe start-process
1个回答
0
投票

阅读完 nginx 文档后,似乎我必须

nginx.exe
文件位于同一位置,才能在启动它时正常工作。所以我的问题与powershell无关,而是与nginx本身有关。不是很方便,但有用!

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