Batch File – Passing ‘Enter Key’ into Nested Programs with MPIExec

batch-file

What i need: To send "enter" key when batch is still processing a previous line.

I am trying to use batch to have an .exe run through a series of input files. The batch file below runs a program, creates an output file, copies it, and then cleans the folder to run through the next set of input variables.

The problem is that after running the .exe, it says "press enter to continue".

@if (@CodeSection == @Batch) @then
set SendKeys=CScript //nologo //E:JScript "%~F0"

for %%i IN (1,2,3) do (
    mpiexec --ppn 20 myprogram "input%%i.input"
    %SendKeys% "{ENTER}"
    xcopy "D:\Original\input%%i-*" "D:\Output\output%%i-*"
    clean.bat
)
pause

goto :EOF
@end
// JScript section
var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.SendKeys(WScript.Arguments(0));

What ive attempted:

  • Use sendkeys after "myprogram", Result: Program still requires enter.
  • Use sendkeys before "myprogram", Result: Program still requires enter.
  • Use sendkeys in conjunction with 'ping'. The delay happens before or after program, so isnt usefull.
  • Attempted to 'pipe' in the sendkeys command. Got an error.

Thoughts?

Best Answer

If I'm understanding the purpose of the mpiexec command correctly, something like

mpiexec --ppn 20 cmd /c "echo . | myprogram "input%%i.input""

should work.

(You may have to adjust the syntax slightly, particularly with regards to the nested quote marks.)

Related Topic