Java似乎正在发送回车到一个subprocess?

我正在使用Java来处理运行subprocess的开销。 subprocess是Microsoft Compute Cluster Pack(如果这是相关的)。 当我在命令行运行MSCCP时,一切都很好,我在提示中进行交互,每个人都很高兴。 当我尝试在Java中做同样的事时,subprocess似乎像无限回车正在发送到它的标准input。 (当我在命令提示符下运行这个进程,并且一遍又一遍地敲回车,它显示出与我在Java中运行时相同的行为)。 这是我的Java代码,非常标准:

List<String> params = Arrays.asList("cmd.exe", "/c", "job.cmd", "submit", stderr, stdout, cwd, scheduler, name, user, run, bif); final Process p = new ProcessBuilder(params).redirectErrorStream(true).directory(location).start(); 

为了保持问题简洁,假设所有variables都设置正确。 他们是 – 我跑了一个循环,打印他们的控制台,然后复制并直接粘贴到我的命令提示符,并运行。 其他variables,如下面write是BlockingQueues。 在单独的线程中,我正在监听stdout / err和stdin:

 // Thread for writing to sub-process' input stream when Queue has char[] in it new Thread(new Runnable() { public void run() { char[] writeThis; PrintWriter procIn = new PrintWriter(p.getOutputStream(), true); try { //write is a BlockingQueue which contains input to the program. while ((writeThis = write.take()) != null) { wait.set(true); for (int i = 0; i < writeThis.length; i++) { procIn.print(writeThis[i]); writeThis[i] = 0; //clearing buffer for security reasons. } procIn.println(); //the only carriage return I intend to send... wait.set(false); } } catch (InterruptedException e) { e.printStackTrace(); } } }).start(); // Thread for listening to the stdout/stderr of the sub-process and reacting to its output. new Thread(new Runnable() { public void run() { Scanner procOut = new Scanner(p.getInputStream()); StringBuffer reqs = new StringBuffer(); while (procOut.hasNext()) { String str = procOut.next() + " "; reqs.append(str); if (reqs.toString().startsWith("Enter the password for")) { // do stuff... } else if (str.contains(")")) { // do stuff... } pauseTillWaitFalse(); } } }).start(); 

我注意到,进程的输出( procOut )如同回车一直被发送到job.cmdsubprocess那样输出输出。 我希望在procIn发送的命令根本不会被发送! 它好像procIn去NUL什么的。

需要注意的是job.cmd是一个内部调用实际运行subprocess的VB脚本的文件。 @%windir%\system32\cscript.exe //Nologo "%~dp0%~n0.vbs" %*其中job.vbs是正在运行的内容。

再一次,这一切在命令提示符下运行完全正常。 我不明白为什么使用Java Process API运行它将会有所不同,除非命令提示符在后台发布某种稳定性命令以保持job.vbs快乐?

编辑:只是为了平息任何可能的困惑,input参数stdout,stderr与进程标准out / in没有任何关系。 他们必须做一些特定于job.cmd系统的其他东西。

更新:我发现在VB代码要求的密码。 有一个部分是这样的:

  Set objPassword = CreateObject("ScriptPW.Password") if IsObject(objPassword)=false then WScript.StdErr.WriteLine "Not support password to be * or empty on Vista or Longhorn." WScript.Quit(1) end if 

所以看起来VB的ScriptPW.Passwordfunction对Java不是很好用。 有没有办法解决? (我仍然宁愿使用这个作为传输密码的方法)。