0

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?

  • **1.** Use [`CALL clean.bat`](https://ss64.com/nt/call.html); then control will return to just after the initial CALL statement.. **2**. Use `%SendKeys% "{ENTER}"` before `mpiexec`. **3.** Consider adding `WScript.Sleep(100);` in the _JScript section_ ; the interval (in milliseconds) to sleep could depend on actual timing. – JosefZ May 31 '19 at 19:29
  • @JosefZ Ive made the following changes: for %%i IN (1,2,3) do ( %SendKeys% "{ENTER}" mpiexec --ppn 20 myprogram "input%%i.input" xcopy "D:\Original\input%%i-*" "D:\Output\output%%i-*" CALL clean.bat ) Ive also added the sleep command. The problem is that it is waiting, and then executing MPIexec. Not executing MPIexc and then doing sendkeys – Shane_Wilson009 May 31 '19 at 19:38
  • Please do not post code snippets in comments (here you can't format the code properly). Use the [edit] button rather. Honestly, I can't help because I use a simple _fast_ executable instead of `mpiexec` (I suppose it's an executable as well) and can't mimic that 15 seconds… Do come the `"press enter to continue"` request from `mpiexec` or from `myprogram`? – JosefZ May 31 '19 at 20:58
  • @JosefZ Good question. I ran the program by itself without the MPIexec parallel aspects, 'myprogram "input1.in" ', and the press enter still came up. So it seems it is a product of the program itself and not MPIexec. The program isn't something i can edit unfortunately, my company licences it. – Shane_Wilson009 May 31 '19 at 21:09
  • Have you tried `echo. | myprogram args` to see whether that bypasses the "press enter to continue" prompt? – Harry Johnston May 31 '19 at 23:22
  • An another thought: run `mpiexec` asynchronously in their own window, something like `start "input%%i.input" mpiexec --ppn 20 myprogram "input%%i.input" & >NUL TIMEOUT 15 /nobreak & %SendKeys% "{ENTER}" "input%%i.input"` where the _JScript section_ should change as `WshShell.AppActivate(WScript.Arguments(1)); WScript.Sleep(100); WshShell.SendKeys(WScript.Arguments(0));` – JosefZ Jun 01 '19 at 14:08
  • @HarryJohnston `echo. | myprogram` works. However, im having some issues getting it to work with MPIexec, for example `echo. | mpiexec --ppn 20 myprogram args` does not.. Is there anyway to use this technique within the context of the MPI program calling myprogram? – Shane_Wilson009 Jun 03 '19 at 14:59

1 Answers1

0

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.)

Harry Johnston
  • 6,005
  • 4
  • 35
  • 52