|
Answer» I am still pretty new to batch files, but am getting a handle on the simple things. Some of the more complex syntax is still a mystery to me and I think that's the help I could use. I've looked at these forums quite a bit, but some of the scripting you all do is pretty wild and sometimes difficult to get a handle on.
I am working on a batch file that will START an executable that communicates with a SERIAL device through a comport. This executable requires three parameters when it is run: port, baudrate, and timeout. The syntax of the executable will be: program.exe /port /baudrate /timeout
I would like the user to be able to select the values of the parameters from a menu and have them saved to a file so they can be referenced again when the batch file is run the next time. My menus appear to be working fine. Where I am having difficulty is in placing the parameters in a file, retrieving them BACK, and using the retrieved data to make comparisons. When exporting the parameter data, a space and carriage return are being added which is causing problems when comparing data.
The values of the parameters will be limited to the following: comport: com1, com2, com3, com4 baudrate: 2400, 4800, 9600, 19200, 38400, 56800 timeout: 10, 30, 60, 90
So far, I have created a file as a storage place for each parameter: comport.txt, baudrate.txt, and timeout.txt. I am not sure if this is the best way to save the parameters, but since I am still learning, I was trying to keep it simple. I am open to other ideas as WELL as long as the scripting is not too complex.
So far, the only method of exporting that I understand is to do the following, but exporting in this manner adds a space and carriage return to the data file: Code: [Select]echo com1 > port.txt and to import: Code: [Select]set /p _port=<port.txt Lastly, as the syntax above shows (program.exe /port /baudrate /timeout), I will eventaully need to string the command together with the three paramters that includes the slash(/). I hope the slash(/) does not make things more difficult.
I am using XP Pro. The batch file will be used on on XP and 2000.
Any help is appreciated...Thank youPersisting data in a file is a time honored tradition. With your menu system already in place, this batch snippet shows how to dump the parameters into a file and extract them out again.
Code: [Select]@echo off if exist parms.txt goto persist set /p port=Enter Ports (1-4): set /p baud=Enter BAUD rate: set /p timeout=Enter time out: echo COM%port%,%baud%,%timeout% > parms.txt
:persist for /f "tokens=1-3 delims=," %%i in (parms.txt) do ( set port=%%i set baud=%%j set timeout=%%k ) . . You can use %port%, %baud%, and %timeout% as needed in the rest of your code .
In it's simplest FORM, the code merely prompts for the information and then dumps the parameters into a file (echo COM%port%,%baud%,%timeout% > parms.txt). It then uses a FOR loop to extract them back out from the file. If I understood you right, the first time thru you want to create the parameter file and after that, extract the parms from the file you already created. The IF statement (if exist parms.txt goto persist) will take care of that logic.
Hope this helps. 8-)
PS. I used a comma as the delimiter in the file, but you can use any character you want; just be sure to also change the FOR delims= parameter.This is very cool. I will have to chew on that for a bit.
BTW, it's so obvious that you guys keep a great forum. Thank you very much.
|