Programme called from R asking for response in certain contexts - how can I feed the answer from R?
I am trying to run a programme using R, using the system
function.
I put system("<prog_name>.exe <control_file_name>")
. This works in general, but sometimes the programme asks for a decision (or response) from the user. I've pasted the message at the bottom. I can do this directly through the command prompt no problem, but I can't get R to feed the response ("1"
) to cmd.exe using the system
function. I'd love to be able to automate the running of this programme in all circumstances, so that it can be linked with other code.
Sorry not to give a reproducible example - can't think how I'd do that here.
Attempts so far:
I've tried making a small batch file with "1" on the second line, but no success. Anyway, the "1" shouldn't go on the next line of the console, but be fed during the running of the programme, so wouldn't expect that to work.
Also tried system("<prog_name>.exe <control_file_name> 1")
and system("<prog_name>.exe <control_file_name> \n 1")
.
This question might have some hints, but it seems to be a slightly different problem and the given approach didn't work either: `system()` interactive .exe/binary from R/Rgui
Message that gets fed back. No problem from command prompt, but I can't get R to give the response
MODPATH 5.0
THIS RUN WILL GENERATE A COMPOSITE BUDGET FILE THAT CONTAINS:
1119597536. BYTES ( 1067.73 Mb)
YOU CAN CONTINUE OR STOP NOW.
SELECT AN OPTION:
1 = CONTINUE
2 = STOP NOW, DO NOT GENERATE THE FILE