Java stuck in infinite loop executing a wmic command on Windows Server 2003

后端 未结 2 1255
伪装坚强ぢ
伪装坚强ぢ 2021-01-23 00:29

I\'m trying to get a list of running processes and their file paths on a Windows Server 2003 machine. I\'m using the following code to try and do that:

protected         


        
2条回答
  •  一向
    一向 (楼主)
    2021-01-23 01:24

    Remember the BufferedReader.readLine() operation will block if there the end of input has not been reached, see here.

    I think what you are experiencing is explained in the API for Process:

    The methods that create processes may not work well for special processes on certain native platforms, such as native windowing processes, daemon processes, Win16/DOS processes on Microsoft Windows, or shell scripts. The created subprocess does not have its own terminal or console. All its standard io (i.e. stdin, stdout, stderr) operations will be redirected to the parent process through three streams (getOutputStream(), getInputStream(), getErrorStream()). The parent process uses these streams to feed input to and get output from the subprocess. Because some native platforms only provide limited buffer size for standard input and output streams, failure to promptly write the input stream or read the output stream of the subprocess may cause the subprocess to block, and even deadlock.

提交回复
热议问题