성태의 닷넷 이야기
홈 주인
모아 놓은 자료
프로그래밍
질문/답변
사용자 관리
사용자
메뉴
아티클
외부 아티클
유용한 코드
온라인 기능
MathJax 입력기
최근 덧글
[정성태] Java - How to use the Foreign Funct...
[정성태] 제가 큰 실수를 했군요. ^^; Delegate를 통한 Bein...
[정성태] Working with Rust Libraries from C#...
[정성태] Detecting blocking calls using asyn...
[정성태] 아쉽게도, 커뮤니티는 아니고 개인 블로그입니다. ^^
[정성태] 질문이 잘 이해가 안 됩니다. 우선, 해당 소스코드에서 ILis...
[양승조
] var대신 dinamic으로 선언해서 해결은 했습니다. 맞는 해...
[양승조
] 또 막혔습니다. ㅠㅠ var list = props[i].Ge...
[양승조
] 아. 감사합니다. 어제는 안됐던것 같은데....정신을 차려야겠네...
[정성태] "props[i].GetValue(props[i])" 코드에서 ...
글쓰기
제목
이름
암호
전자우편
HTML
홈페이지
유형
제니퍼 .NET
닷넷
COM 개체 관련
스크립트
VC++
VS.NET IDE
Windows
Team Foundation Server
디버깅 기술
오류 유형
개발 환경 구성
웹
기타
Linux
Java
DDK
Math
Phone
Graphics
사물인터넷
부모글 보이기/감추기
내용
<div style='display: inline'> <h1 style='font-family: Malgun Gothic, Consolas; font-size: 20pt; color: #006699; text-align: center; font-weight: bold'>Windows Server 2008 R2 환경에서 Powershell을 psexec로 원격 실행할 때 hang이 발생하는 문제</h1> <p> 요일을 기준으로,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Setting a windows batch file variable to the day of the week ; <a target='tab' href='https://stackoverflow.com/questions/11364147/setting-a-windows-batch-file-variable-to-the-day-of-the-week'>https://stackoverflow.com/questions/11364147/setting-a-windows-batch-file-variable-to-the-day-of-the-week</a> </pre> <br /> 명령어를 실행하려고 powershell의 도움을 받으려고 했는데,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > for /f %%d in ('"powershell (Get-Date).DayOfWeek.Value__"') do set DowNum=%%d if %DowNum% == 2 ( echo "test1" ) else ( echo "test2" ) </pre> <br /> 희한하게 <a target='tab' href='https://docs.microsoft.com/en-us/sysinternals/downloads/psexec'>psexec.exe를 이용해 원격 실행</a>을 할 때 Windows Server 2008 R2 컴퓨터에 대해서만 (한참 동안) 대기 현상이 발생합니다. (그 이후의 운영체제에서는 괜찮습니다.) <br /> <br /> 실제로 다음과 같이 간단하게 재현할 수 있습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > C:\temp> <span style='color: blue; font-weight: bold'>psexec \\win2008r2 powershell (Get-Date).DayOfWeek.Value__</span> PsExec v2.11 - Execute processes remotely Copyright (C) 2001-2014 Mark Russinovich Sysinternals - www.sysinternals.com <span style='color: blue; font-weight: bold'>2</span> </pre> <br /> 저렇게 결과까지 출력한 상태에서 한참 동안 반응이 없다가 오류 메시지와 함께 종료합니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Error communicating with PsExec service on win2008r2: The pipe has been ended. </pre> <br /> 조금이라도 단서를 잡기 위해 hang이 걸렸을 때 powershell.exe의 덤프를 떠 보면,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > 0:000> <span style='color: blue; font-weight: bold'>!clrstack</span> OS Thread Id: 0x2c70 (0) Child-SP RetAddr Call Site 000000000021d540 000007fe98d3e3cf DomainNeutralILStubClass.IL_STUB(Microsoft.Win32.SafeHandles.SafeFileHandle, Byte*, Int32, Int32 ByRef, IntPtr) 000000000021d660 000007fe98d3e20a System.IO.FileStream.ReadFileNative(Microsoft.Win32.SafeHandles.SafeFileHandle, Byte[], Int32, Int32, System.Threading.NativeOverlapped*, Int32 ByRef) 000000000021d6d0 000007fe98d3de82 <span style='color: blue; font-weight: bold'>System.IO.FileStream.ReadCore</span>(Byte[], Int32, Int32) 000000000021d750 000007fe98d3dc97 System.IO.FileStream.Read(Byte[], Int32, Int32) 000000000021d7c0 000007fe99082f8c System.IO.StreamReader.ReadBuffer() 000000000021d810 000007fe990824cf System.IO.StreamReader.ReadLine() 000000000021d860 000007fe990823b5 System.IO.TextReader+SyncTextReader.ReadLine() 000000000021d8c0 000007fe9907d76e Microsoft.PowerShell.WrappedDeserializer..ctor(DataFormat, System.String, System.IO.TextReader) 000000000021d900 000007fe98b4ddb9 <span style='color: blue; font-weight: bold'>Microsoft.PowerShell.Executor.ExecuteCommandAsyncHelper</span>(System.Management.Automation.Runspaces.Pipeline, System.Exception ByRef, ExecutionOptions) 000000000021d9b0 000007fe98b4cfd5 Microsoft.PowerShell.ConsoleHost.CreateRunspace(System.String, Boolean, Boolean, Boolean, System.Collections.ObjectModel.Collection`1<System.Management.Automation.Runspaces.CommandParameter>) 000000000021da90 000007fe98b4ceca Microsoft.PowerShell.ConsoleHost.DoRunspaceLoop(System.String, Boolean, System.Collections.ObjectModel.Collection`1<System.Management.Automation.Runspaces.CommandParameter>, Boolean, Boolean) 000000000021db30 000007fe98b372da Microsoft.PowerShell.ConsoleHost.Run(Microsoft.PowerShell.CommandLineParameterParser, Boolean) 000000000021dba0 000007fe98b36f7f Microsoft.PowerShell.ConsoleHost.Start(System.Management.Automation.Runspaces.RunspaceConfiguration, System.String, System.String, System.String, System.String[]) 000000000021dc50 000007fe98926196 Microsoft.PowerShell.ConsoleShell.Start(System.Management.Automation.Runspaces.RunspaceConfiguration, System.String, System.String, System.String, System.String[]) 000000000021dcd0 000007fef8158982 Microsoft.PowerShell.UnmanagedPSEntry.Start(System.String, System.String[]) 000000000021e5e0 000007fe98924cf6 System.Reflection.RuntimeMethodInfo.Invoke(System.Object, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo, Boolean) 000000000021e780 000007fef8158982 System.Reflection.RuntimeMethodInfo.Invoke(System.Object, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo) </pre> <br /> 보는 바와 같이 (흔히 Execution Policy에 따른 질문을 하는 등의 반응이 아닌) 단순히 Command를 실행하며 마저 읽지 못한 입력을 계속 기다리는 듯한 결과를 보여줍니다.<br /> <br /> 결국 해답을 찾지 못하고 검색하다가 ^^ 알게 되었는데,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Why does my PowerShell script hang when called in PSEXEC via a batch (.cmd) file? ; <a target='tab' href='https://serverfault.com/questions/135070/why-does-my-powershell-script-hang-when-called-in-psexec-via-a-batch-cmd-file'>https://serverfault.com/questions/135070/why-does-my-powershell-script-hang-when-called-in-psexec-via-a-batch-cmd-file</a> </pre> <br /> 잘 알려진 문제라고 하면서 다음과 같이 NUL 입력 처리를 하면 된다고 합니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > C:\temp> <span style='color: blue; font-weight: bold'>psexec \\win2008r2 powershell (Get-Date).DayOfWeek.Value__ < NUL</span> PsExec v2.11 - Execute processes remotely Copyright (C) 2001-2014 Mark Russinovich Sysinternals - www.sysinternals.com <span style='color: blue; font-weight: bold'>2</span>powershell exited on win2008r2 with error code 0. </pre> <br /> 하지만, 보는 바와 같이 결과는 나오지만, 출력이 "powershell exited on win2008r2 with error code 0." 메시지와 같은 줄에 나오면서 좀 우아하지 않습니다. 다행히 동일한 글타래에서 좀 더 나은 답변이 나오는데요,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > C:\temp> <span style='color: blue; font-weight: bold'>psexec \\win2008r2 powershell -inputformat none (Get-Date).DayOfWeek.Value__</span> PsExec v2.11 - Execute processes remotely Copyright (C) 2001-2014 Mark Russinovich Sysinternals - www.sysinternals.com <span style='color: blue; font-weight: bold'>2</span> powershell exited on win2008r2 with error code 0. </pre> <br /> "-inputformat none" 옵션을 주면 됩니다. ^^<br /> <br /> (그나저나 PowerSHell을 줄여서 POSH라고 한다는 것은 처음 알았군요. ^^)<br /> </p><br /> <br /><hr /><span style='color: Maroon'>[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]</span> </div>
첨부파일
스팸 방지용 인증 번호
1394
(왼쪽의 숫자를 입력해야 합니다.)