powershell을 사용하면 '&'문자를 사용하여 다른 응용 프로그램을 실행하고 매개 변수를 전달할 수 있습니다.동적으로 명령 줄 명령을 생성 한 다음 powershell을 사용하여 호출하십시오.
간단한 예입니다.
$notepad = 'notepad'
$fileName = 'HelloWorld.txt'
# This will open HelloWorld.txt
& $notepad $fileName
좋은 결과입니다. 하지만 비즈니스 로직을 사용하여 명령 문자열을 동적으로 생성하려면 어떻게해야합니까? 같은 간단한 예제를 사용 :
$commandString = @('notepad', 'HelloWorld.txt') -join ' ';
& $commandString
내가 오류를 얻을 :
The term 'notepad HelloWorld.txt' 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.
를 내 실제 예제는 동적으로 최종 명령 행 문자열에 옵션을 추가하거나 제거 할 노력하고있어. 이 문제를 해결할 수있는 방법이 있습니까? 이 작업을 수행하는
큰 따옴표 ("") 도움에 인용 하는가? – cristobalito