1

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
Community
  • 1
  • 1
CJB
  • 1,759
  • 17
  • 26
  • 1
    Usually, options passed at the command line are named. [check page 19 and following](http://pubs.usgs.gov/tm/6a41/pdf/TM_6A_41.pdf) for a name that corresponds to your option: – Pierre Lapointe Dec 18 '15 at 15:06
  • Wow - thank you for looking up the documentation! MODPATH 6 is actually quite different from version 5, but you have set me on the right track and I have now asked the author of the software. Will report back. – CJB Dec 18 '15 at 15:45
  • You should download the latest version then. [On this site](http://water.usgs.gov/ogw/modpath/index.html) – Pierre Lapointe Dec 18 '15 at 16:05

0 Answers0