PowerShell에서 실행 파일을 실행할 때 경로에 공백이 있으면 작동하지 않습니다.

PowerShell에서 실행 파일을 실행할 때 경로에 공백이 있으면 작동하지 않습니다.

PowerShell 프롬프트에서 다음을 수행합니다.

\Windows\system32\mspaint.exe

페인트를 실행합니다. 그럴 것이다

Invoke-Expression -command "\Windows\system32\mspaint.exe"

그러나 경로에 공백이 있으면 PowerShell은 더미를 뱉어냅니다. 예:

Invoke-Expression -command "\install\sub directory\test.bat"

불평하는 것 :

The term '\install\sub' is not recognized as the name of a cmdlet, function, script file, or operable program.

내가 무엇을 놓치고 있나요?

답변1

에 따르면이것Technet의 기사에서는 경로를 큰따옴표로 묶는 것만으로는 충분하지 않습니다.

사용하려는 경로에는&(앰퍼샌드)를 디렉토리 앞에 붙이지 않으면 작동하지 않습니다.

예를 들어:

Invoke-Expression -command & "\install\sub directory\test.bat"

답변2

가장 간단한 방법은 호출 연산자를 사용하는 것입니다.

&'String containing the path'

실행 파일을 시작하는 것은 Invoke-Expression실제로 잘못된 cmdlet이므로 Start-Process.

관련 정보