如何设置当前工作文件夹的位置?

时间:2020-03-19 04:30:27

标签: windows powershell

我有一个Powershell脚本位于“ register”文件夹中,我想用来执行该脚本,而exe文件也位于“ app”子文件夹中,该文件夹也动态位于“ register”文件夹中。每次运行脚本时,都会出现“找不到路径”错误,但我希望Powershell保持当前的工作文件夹位置,以便每次复制到另一个驱动器时它都可以工作。

下面是我的代码的回顾

"cmd.exe /c PowerShell.exe -windowstyle hidden Start-Process '.\Register\App\record.exe'"

谢谢。

1 个答案:

答案 0 :(得分:0)

尚不清楚您的命令在何处执行,但我相信周围的双引号会将其中的所有内容都视为可执行文件名,而不仅仅是cmd.exe

如果我在Command Prompt打开%UserProfile%并将%SystemRoot%\system32\calc.exe复制到%UserProfile%\Register\App\record.exe,那么对我来说以下工作:

  • Command Prompt,不带双引号:cmd.exe /c PowerShell.exe -windowstyle hidden Start-Process '.\Register\App\record.exe'
  • PowerShell,不带双引号:PowerShell.exe -windowstyle hidden Start-Process '.\Register\App\record.exe'

这两个...

  • Command Prompt,并用双引号引起来:"cmd.exe /c PowerShell.exe -windowstyle hidden Start-Process '.\Register\App\record.exe'"
  • PowerShell,并用双引号引起来:"PowerShell.exe -windowstyle hidden Start-Process '.\Register\App\record.exe'"

...导致...

系统找不到指定的路径。

此外,以防万一,您正在尝试运行cmd.exe来运行powershell.exe来运行record.exe。至少cmd.exe /c是不必要的;只需直接运行PowerShell