1

I am trying to run batch of .sav files in CPLEX Interactive Optimizer. IBM provides some documentation here. However, I am facing a few issues:

  1. After launching the CPLEX Interactive Optimizer, when drag and drop my batch file (batch_trial.bat) from its location (C:\Users\myname\folder name\) into the CPLEX command prompt (that is, when I hit enter after CPLEX>C:\Users\myname\folder name\batch_trial.bat, I get the error that Command '"C:\Users\myname\folder' does not exist. Type 'help' for a list of commands. I understand from some forums that this is because of the 'space' in folder name, however, the answers in those forums said that using double quotation marks would solve this issue. But I use double quotation marks and I still see the error.
  2. I tried entering the batch file contents directly into the CPLEX prompt, like this (this is the contents of batch_trial.bat, as suggested by IBM's documentation):

    CPLEX> @echo off
    for /L %%i in (1,1,2) do (
    move mytest%i.sav mytest.sav
    cplex < mycplexcommands
    move cplex.log mytest%i.log
    )
    

    This doesn't work either: For each of @echo, for, move, cplex I get similar errors saying that these commands do not exist. I have the two mytest1.sav, mytest2.sav, and mycplexcommands.txt in C:\Users\myname\folder name\. The contents of mycplexcommands.txt is:

    read mytest.sav
    optimize
    display solution variables 1-10
    quit
    
  3. What if I don't have similar names for the .sav files? For example, if the files names are apg.sav and hfb.sav, how do I still get these to be executed by the for loop in the batch file?

Thank you!

2 Answers2

1

If you run your code from a .bat file use %%i in the declaration of your FOR loop and in the rest of your code.

move "mytest%%i.sav" "mytest.sav"

If you run the code block directly in the shellthen use %i in the declaration and in the code.

SachaDee
  • 9,245
  • 3
  • 23
  • 33
1

It sounds like you are confused about the difference between a batch file (a file with a .bat extension) and a command file used by the CPLEX interactive. A batch file can be run from the Windows command shell. A CPLEX command file can be run by the interactive when using the redirection operator (<, as in your example) or the -f option. For example, the -f options can be used, like so:

cplex.exe -f mycplexcommands.txt

For (1) and (2), things are not working because you are trying to run a batch script from within the CPLEX interactive. What may work is if you drag your mycplexcommands.txt file into the CPLEX interactive instead.

For (3), see the stackoverflow thread at How to do a for loop in windows command line? That is, it should start like (this has not been tested):

FOR %%i IN (*.sav) DO

Lastly, you may be interested in looking at the Open LP files in CPLEX interactive article on developerWorks.

rkersh
  • 4,447
  • 2
  • 22
  • 31
  • thanks for your answer. Dragging and dropping `mycplexcommands.txt` doesn't work either:`CPLEX>C:\Users\myname\folder name\batch_trial.bat` gives the error `Command '"C:\Users\myname\folder' does not exist. Type 'help' for a list of commands.` Your suggestion to (3) may help once I fix (1) and (2). – Vineet Payyappalli Jun 06 '18 at 12:51
  • Your comment indicates that you are still trying to read/run a `.bat` file in the CPLEX interactive. You can _not_ do that! – rkersh Jun 06 '18 at 18:53
  • Thanks for the comment. Sorry, there was a mistake in my above comment. I am not able to edit it now. I was trying to run `.txt` file and not a `.bat` file. Running `CPLEX>C:\Users\myname\folder name\mycplexcommands.txt` gave the same error: `Command 'C:\Users\myname\folder' does not exist. Type 'help' for a list of commands.` – Vineet Payyappalli Jun 06 '18 at 21:03