Ms-Dos - Se puede utilizar un fichero de parametros???

 
Vista:

Se puede utilizar un fichero de parametros???

Publicado por Jose (1 intervención) el 24/08/2006 13:08:23
Me gustaría utilizar un fichero de parámetros en un BAT, de manera que por ejemplo:

en lugar de llamar a un programa así

programa.bat Primero Segundo Tercero

y despues utilizar %1, %2 y %3 dentro de programa.bat

lo que me gustaria sería llamar al programa así:

programa.bat FitPar.txt

y en FitPar.txt tener una lista de parámetros (uno por línea) de manera que se pudieran utilizar desde programa.bat de alguna manera..


Es muy complicado?

gracias por anticipado!!!

José
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:Se puede utilizar un fichero de parametros???

Publicado por Antoni Masana (295 intervenciones) el 25/08/2006 06:35:53
No es complicado, es simplemente imposible con las herramientas del MS-DOS.

Pero si utilizas herramientas externas ya es otra cosa. Uno de estos programas es el LISTMOD lee por la entrada estandar los parametros y crea por la salida estandar el BAT

La ayuda del programa es esta (lo puedes encontrar si lo buscas con google)

LISTMOD Ver 1.1 (c) 1994 Horst Schaeffer
-----------------------------------------

LISTMOD generates an output list (to STDOUT) using data from a given
input list (STDIN).

Syntax: LISTMOD [options] string < input.txt > output.txt

The string is written into each output line, where $1...$99 may be
used as variables referring to the 1st....99th word of the input
line.

If, for example, you want to execute: COPY <file> A:
for each file name in a given list, LISTMOD will generate a COPY
instruction for each file name and write it into a batch file.

listmod COPY $1 A: > TMP.BAT
:: ==========
call TMP.BAT

The file names are inserted by $1 referring to the 1st (and only)
word of each input line.

Variables and other symbols
---------------------------
$1..$99 refers to the n-th word of the input line
$0 the complete input line
$* same as $0
$( $! $) converts to: < | >
$# generates the 3-digit line number (see option /N)
$$ $
$L generates a carriage return / line feed.
(more than 1 line may be produced from each input line)

Options
-------
Options must be placed before the string.
/S... Separators (see below)
/Nnnn starting number for $# count (default is 001)

Separators
----------
"Words" of an input line are separated by blank, comma, semicolon
or equal sign. These delimiters are never copied to output lines.

Additional separators may be defined with the /S option followed
by one or more symbols (terminated by a space).

Example: delete the 5th character from each *.DAT file name
(in the current directory)

ren *.DAT ????#???.DAT
dir *.DAT /B/A-D | LISTMOD /S# ren $1#$2 $1$2 > TMP.BAT
:: ^^^ ==============
call TMP.BAT

First the 5th character is replaced by "#" (REN).
Then a directory listing is piped into LISTMOD, where the "#"
is defined as an additional separator, dividing the file names
into $1 (????) and $2 (???.DAT).

Notes
-----
The input file is limited to 60 KB. The output file is not limited,
but the output line size must not exceed 1 KB.

If no input file is given LISTMOD shows a brief help information.

To avoid conflicts when numeric data occur in the string, you
may use e.g. $01 instead of $1 (because only 2 digits are read):

$15 is the 15th word
$015 is the 1st word succeeded by constant "5"

*** 02.10.1994
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Se puede utilizar un fichero de parametros???

Publicado por Ion (5 intervenciones) el 25/08/2006 12:51:57
Todo depende de lo que quieras hacer con esos argumentos...
Está claro que los BAT son bastante limitados, pero podrías intentar usar la instrucción "for /F". A ver si esto te sirve de algo:

for /F "delims= tokens=1" %%i in (FitPar.txt) do echo Contenido de linea: "%%i"

En lugar del "echo", podrías llamar a otro .bat, con cada parámetro indicado en el fichero:

for /F "delims= tokens=1" %%i in (FitPar.txt) do call otro.bat "%%i"
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar