Get my parameters from a txt file

View: New views
5 Messages — Rating Filter:   Alert me  

Get my parameters from a txt file

by cwb212001 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi all, I need your help.  I have a program that creates a .txt file
with a 5 digit number as the contents.  I need to have my batch file,
upon opening, extract that number from the .txt file and assign it as
the single variable.  I have found reference to a for loop ...  FOR /f %
%a in (batchinput.txt) do echo "%%a" .  I think this would work for me
if I replaced the    echo "%%a"    with something like   set %1="%%a".  
Would this work?  I appreciate any help.  Thanks, Chris  


Re: Get my parameters from a txt file

by Parag P. Doke :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Chris.
Can you please post contents of the text file in question ?
That will make it a lot easier for people to help you out.

-Parag

On Tue, Oct 14, 2008 at 7:58 AM, cwb212001 <cwb212001@...> wrote:
> Hi all, I need your help. I have a program that creates a .txt file
> with a 5 digit number as the contents. I need to have my batch file,
> upon opening, extract that number from the .txt file and assign it as
> the single variable. I have found reference to a for loop ... FOR /f %
> %a in (batchinput.txt) do echo "%%a" . I think this would work for me
> if I replaced the echo "%%a" with something like set %1="%%a".
> Would this work? I appreciate any help. Thanks, Chris
>
>



--
Parag P. Doke
http://paragpdoke.blogspot.com

Re: Get my parameters from a txt file

by Theodorik OBroin :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Chris,

  Here's how I would do this, there are three files:
1) test.cmd
2) batchinput.txt
3) someotherbatchfile.cmd

  test.cmd runs, and pulls in the numbers from batchinput.txt.
  It then passes each line value (eg. 0001, 0002) and passes it to
  someotherbatchfile.cmd
  This simply echo's the value out to the screen and returns.
  Program completes.

Here's the screen grab showing what test.cmd has, the numbers in
batchinput.txt, and also the contents of someotherbatchfile.cmd.
At the end, it shows the output.
Of course, you will change someotherbatchfile.cmd to do what you
want to do to the numbers.

Hope this helps,
db

--- start of screen grab ---
C:\Documents and Settings\theodorik>dir /b
batchinput.txt
someotherbatchfile.cmd
test.cmd

C:\Documents and Settings\theodorik>type test.cmd
@echo off
setlocal
set IMPORTFILE=batchinput.txt

for /f %%I IN (%IMPORTFILE%) do (
  call :PROCESS %%I
)
goto :END

:PROCESS
call SOMEOTHERBATCHFILE.cmd %1
goto :EOF

:END
endlocal
pause

C:\Documents and Settings\theodorik>type batchinput.txt
0001
0002
0003
0004
0005

C:\Documents and Settings\theodorik>type someotherbatchfile.cmd
echo %1

C:\Documents and Settings\theodorik>test
0001
0002
0003
0004
0005
Press any key to continue . . .

--- end of screen grab ----


2008/10/14 cwb212001 <cwb212001@...>

>   Hi all, I need your help. I have a program that creates a .txt file
> with a 5 digit number as the contents. I need to have my batch file,
> upon opening, extract that number from the .txt file and assign it as
> the single variable. I have found reference to a for loop ... FOR /f %
> %a in (batchinput.txt) do echo "%%a" . I think this would work for me
> if I replaced the echo "%%a" with something like set %1="%%a".
> Would this work? I appreciate any help. Thanks, Chris
>
>  
>


[Non-text portions of this message have been removed]


Re: Get my parameters from a txt file

by foxidrive-7 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, 14 Oct 2008 02:28:48 -0000, "cwb212001" <cwb212001@...>
wrote:

>Hi all, I need your help.  I have a program that creates a .txt file
>with a 5 digit number as the contents.  I need to have my batch file,
>upon opening, extract that number from the .txt file and assign it as
>the single variable.  I have found reference to a for loop ...  FOR /f %
>%a in (batchinput.txt) do echo "%%a" .  I think this would work for me
>if I replaced the    echo "%%a"    with something like   set %1="%%a".  
>Would this work?  I appreciate any help.  Thanks, Chris  

You were almost there.  The double quotes below eliminate any trailing
spaces if they were added accidentally while editing the batch file.

@echo off
FOR /f %%a in (batchinput.txt) do set "variable=%%a"
echo %variable%


and this version will handle spaces etc in the filename, and also in the
contents of the file.  Both version are intended for a single line in the
text file, or if there are multiple lines it will use the last line.

@echo off
FOR /f "delims=" %%a in (
'type "c:\temp\batchinput.txt") do set "variable=%%a"
echo %variable%



Re: Get my parameters from a txt file

by SCMBUILD :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi all ,

I am Trying to pass the parameter from the batch file

Here is the process i am following

batchinput.txt
--------------
FD1 FL1
FD2 FL2
FD3 FL3
FD4 FL4
FD5 FL5
FD6 FL6
FD7 FL7


my batch file

cpy.bat
-------
@echo off
setlocal
set IMPORTFILE=C:\batchinput.txt

for /f %%a IN (%IMPORTFILE%) do (
  call :PROCESS  
  )

:PROCESS  
echo "%%a"
copy "C:\Documents and Settings\bhattu\Desktop\TST\%1\%2\*.txt" "C:\Documents and Settings\bhattu\Desktop\TSTFD\%1\%2\*.txt"


The out put from the batchile is

C:\Documents and Settings\bhattu>for.bat
"%a"
The system cannot find the file specified.
"%a"
The system cannot find the file specified.
"%a"
The system cannot find the file specified.
"%a"
The system cannot find the file specified.
"%a"
The system cannot find the file specified.
"%a"
The system cannot find the file specified.
"%a"
The system cannot find the file specified.
"%a"
The system cannot find the file specified.


but i want to pass the %1 as the FD1 - FD7 and %2 as FL1 - FL7 so that it will copy all the text files in the respective folders

when i am echoing the %%a value it is showing the %a instead of the values in the text file.



when i am trying in the following way it is echoing the values correctly.

cpy1.bat
--------
@echo off
setlocal
set IMPORTFILE=C:\batchinput.txt

FOR /f %%a in (%IMPORTFILE%) do echo "%%a"


the output is
-------------
FD1 FL1
FD2 FL2
FD3 FL3
FD4 FL4
FD5 FL5
FD6 FL6
FD7 FL7


Can you please help me how can i pass the %1 and %2 values to batch file from the text file.