반응형
공백이 있는 문자열을 PowerShell로 전달하려면 어떻게 해야 합니까?
주어진:
# test1.ps1
param(
$x = "",
$y = ""
)
&echo $x $y
다음과 같이 사용:
powershell test.ps1
출력:
> <blank line>
하지만 이것은 잘못된 것입니다.
test.ps1 -x "Hello, World!" -y "my friend"
출력:
Hello,
my
저는 다음을 보기를 기대했습니다.
Hello, World! my friend
음, 이건.cmd.exe
문제입니다. 하지만 그것을 해결할 몇 가지 방법은
작은 따옴표 사용
powershell test.ps1 -x 'hello world' -y 'my friend'
사용
-file
논쟁powershell -file test.ps1 -x "hello world" -y "my friend"
작성
.bat
다음 내용이 포함된 포장지@rem test.bat @powershell -file test.ps1 %1 %2 %3 %4
그런 다음에 다음과 같이 부릅니다.
test.bat -x "hello world" -y "my friend"
백틱을 사용하여 공백을 이스케이프할 수 있습니다.
PS & C:\Program` Files\\....
제 경우 가능한 해결책은 단일 인용문과 이중 인용문을 내포하는 것이었습니다.
test.ps1 -x '"Hello, World!"' -y '"my friend"'
저도 비슷한 문제가 있었지만, 저의 경우 cmdlet을 실행하려고 했고, 통화는 Cake 스크립트 내에서 이루어지고 있었습니다.이 경우 단일 따옴표와-file
인수가 작동하지 않았습니다.
powershell Get-AuthenticodeSignature 'filename with spaces.dll'
결과 오류:Get-AuthenticodeSignature : A positional parameter cannot be found that accepts argument 'with'.
가능하다면 배치 파일은 피하고 싶었습니다.
해결책
/S와 함께 cmd 래퍼를 사용하여 외부 따옴표를 풀었습니다.
cmd /S /C "powershell Get-AuthenticodeSignature 'filename with spaces.dll'"
언급URL : https://stackoverflow.com/questions/28311191/how-do-i-pass-in-a-string-with-spaces-into-powershell
반응형
'sourcecode' 카테고리의 다른 글
php에서 데이터베이스 데이터를 비교하는 방법 (0) | 2023.08.11 |
---|---|
VBA: 추상 수업 같은 것이 있나요? (0) | 2023.08.11 |
Asp에서 로그인한 사용자의 사용자 ID를 가져옵니다.넷 MVC 5 (0) | 2023.08.11 |
데이터베이스 스키마가 null 가능한 열에 대해 동기화되지 않았습니다. (0) | 2023.08.11 |
활동 중 카메라 및 디스플레이에서 이미지 캡처 (0) | 2023.08.11 |