使用 bat 脚本调用 powershell 脚本时遇到的问题

如果 powershell 脚本中,有一些涉及相对路径的操作,会发现这样运行的 powershell 并不是在期望的目录中,需要重新设置一下当前工作目录:

powershell -Command Set-Location -LiteralPath "%cd%"; ".\test.ps1"

通过 Set-Location 命令即可实现此需求。

参考:https://stackoverflow.com/questions/69404268/how-to-change-the-current-directory-using-bat-file-in-windows-powershell

posted @ 2023-07-25 14:50  不是豆豆  阅读(169)  评论(0编辑  收藏  举报
友情链接:迷途