带空格的Powershell打开文件路径 [英] Powershell Opening File Path with Spaces
问题描述
我是我的PS脚本,我希望能够通过执行以下操作在另一个PS实例中运行另一个脚本:
Im my PS script I want to be able to run another script in another PS instance by doing the following:
$filepath = Resolve-Path "destruct.ps1"
start-process powershell.exe "$filepath"
destruct.ps1与该脚本位于同一文件夹中
destruct.ps1 is in the same folder as this script
但是,在包含空格("C:\ My Scripts \")的位置运行此脚本时,会出现以下错误:
However when running this script in a location which includes spaces ("C:\My Scripts\") i will get the following error:
术语"C:\ My"不能识别为cmdlet,函数,可操作程序或脚本文件.验证条款并重试.
我知道使用'&'使用Invoke-Expression方法可以解决此问题,但是如何使用start-process方法来解决?
I know by using a '&' with the Invoke-Expression method solves this problem, how can i do the same but by using the start-process method?
非常感谢您的帮助!
推荐答案
尝试一下:
start-process -FilePath powershell.exe -ArgumentList "-file `"$filepath`""
评论后
start-process -FilePath powershell.exe -ArgumentList "-file `"$($filepath.path)`""
旁注:
$filepath
是[pathinfo]
类型,而不是[string]
类型.
$filepath
is a [pathinfo]
type and not a [string]
type.
这篇关于带空格的Powershell打开文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!