RunProgram을 사용하여 스피치마크 ""를 powershell로 구문 분석할 수 없습니다.안녕하세요, 예를 들어 powershell 실행에 문제가 있습니다.
cmd = EvalInsert(
"\[$imageFile = "test"]\");
rp1 = RunProgram(Executable("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" ),
Options(Eval(cmd)),
ReadFunction("text")
);사용하려는 실제 cmd는 더 복잡하지만 스피치마크와 동일한 문제가 있습니다. 로그에 rp1을 인쇄하면 다음이 제공됩니다.
"test : The term 'test' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:14
+ $imageFile = test
+ ~~~~
+ CategoryInfo : ObjectNotFound: (test:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
" 이는 라인이 스피치마크 없이 실행되었음을 의미합니다.
스피치마크가 올바르게 실행되도록 하려면 어떻게 해야 합니까?
도움을 주셔서 미리 감사드립니다.
Re: RunProgram을 사용하여 powershell에서 ""를 구문 분석할 수 없습니다.방금 윈도우 명령줄, 따옴표, 이스케이프에 대한 훌륭한 설명을 우연히 발견했는데, 왜 그렇게 어려운지 설명해 주셨어요.
http://www.windowsinspired.com/the-corright-way-to-quote-command-line-arguments/
http://www.windowsinspired.com/understanding-the-command-line-string-and-arguments-received-by-a-windows-program/
http://www.windowsinspired.com/how-a-windows-programs-splits-its-command-line-into-individual-arguments/
너무 단순화해서 말하면, 명령줄의 여러 인수는 공백으로 구분됩니다. 각 따옴표는 인수를 구분하는 데 공백을 사용할지 여부를 토글합니다. \\는 리터럴 \이고 \"는 리터럴 "입니다. 공백을 토글 해제할 때 두 개의 인접한 따옴표는 리터럴 "이 되지만, 공백은 사용되는 파서 변형에 따라 켜거나 끌 수 있습니다.
업데이트 2025년 1월 20일: 링크가 오래되었습니다. 웹 아카이브 버전:
http://web.archive.org/web/20220629215303/http://windowsinspired.com/the-corright-way-to-quote-command-line-arguments/
https://web.archive.org/web/20220629212707/https://www.windowsinspired.com/understanding-the-command-line-string-and-arguments-received-by-a-windows-program/
https://web.archive.org/web/20220629212422/https://www.windowsinspired.com/how-a-windows-programs-splits-its-command-line-into-individual-arguments/
Re: RunProgram을 사용하여 스피치마크 ""를 powershell로 구문 분석할 수 없습니다.powershell 명령줄 구문 분석이 작동하려면 명령줄 인수에 몇 가지 추가 따옴표와 이스케이프가 필요합니다. (Powershell을 사용한 것은 이번이 두 번째입니다. 뭔가 간과하고 있을지도 모릅니다...) (또한 이 웹 페이지 구문 색상 지정은 대괄호 인용 이스케이프에 대해 잘못되었습니다.)
command = "\["$imagefile = \"test\";echo $imagefile"]\";
Write( "\!nthe command is:", command ); // write shows it in the log without extra escapes
result = RunProgram(
executable( "powershell.exe" ), //
options( command ), //
readfunction( "text" )//
);
Show( result );
명령은 다음과 같습니다."$imagefile = \"test\";echo $imagefile"
결과 = "테스트
";
다음은 CMD 창에서 두 번 시도한 화면 캡처입니다.
powershell output in a CMD windowpowershell output in a CMD windowpowershell output in a CMD windowCMD 창에서 powershell 출력
외부 따옴표는 powershell이 단일 옵션을 볼 수 있도록 합니다. powershell이 텍스트를 가져오기 전에 외부 따옴표가 CMD에 의해 제거됩니다. 원래 예에서는 powershell이 받은 세 가지 항목($imagefile, =, test )이 있었고 test 주위의 바깥쪽 따옴표는 CMD에 의해 제거되었습니다. 인수에 따옴표나 공백이 있는 경우 외부 따옴표가 필요합니다.