简体   繁体   English

从Java调用的Powershell脚本挂起

[英]Powershell script invoked from java hangs

I have been looking at a thread java input.readLine hangs after starting a powershell script 我一直在看一个线程java input.readline在启动powershell脚本后挂起

which is exactly what I have done, but in JDK 1.6, we do not have ProcessBuilder - redirectOutput and Redirect to. 这正是我所做的,但是在JDK 1.6中,我们没有ProcessBuilder-redirectOutput和Redirect to。

So is there any way to solve the waiting/hanging? 那么有什么方法可以解决等待/挂机问题吗?

I recommend checking out the Apache Ant library available at http://ant.apache.org/ 我建议检出http://ant.apache.org/上的Apache Ant库。

I've used the 'Exec' task to run git.exe and capture its output. 我使用了“ Exec”任务来运行git.exe并捕获其输出。 I modeled the code after the second option on http://groovy.codehaus.org/Executing+External+Processes+From+Groovy 我在http://groovy.codehaus.org/Executing+External+Processes+From+Groovy上的第二个选项之后对代码进行了建模

I believe real problem is the way how PowerShell handles STDIN stream while running in Java executed console environment. 我认为真正的问题是PowerShell在Java执行的控制台环境中运行时如何处理STDIN流。 I use this trick to run batch scripts with powershell task or direct powershell script execution. 我使用此技巧在Powershell任务中运行批处理脚本或直接执行Powershell脚本。 Add InputFormat none to avoid STDIN hangs. 添加InputFormat none以避免STDIN挂起。

powershell -NoLogo -Noninteractive -InputFormat none -Command "%cmd%"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM