Read File and Use in Batch

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

Read File and Use in Batch

by Ryan Johnson-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I want to have a batch file open a file that I am passing to it as %1, read the data inside that file and use that later in the batch file.

At the command prompt I am typing this:

c:\>email_po.bat C:\Edi\Prod\xlate\i\52122\userexit

The userexit file only has this data in it:

PO_NUMBER=123456

I want to use the value of the PO_NUMBER in %2 in the batch file below:

c:\edisendmail.exe -r ryan.johnson@... -s "PO %2 Received" -t "PO %2 Received"


So the subject of my email would read:

"PO 123456 Received"

How can I have the batch file get the valued after "PO_NUMBER=" so it can be used in my email string?

Thanks,

Ryan Johnson


Re: Read File and Use in Batch

by foxidrive-7 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Fri, 22 May 2009 16:02:04 -0000, "Ryan Johnson"
<ryan.johnson@...> wrote:

>I want to have a batch file open a file that I am passing to it as %1, read the data inside that file and use that later in the batch file.
>
>At the command prompt I am typing this:
>
>c:\>email_po.bat C:\Edi\Prod\xlate\i\52122\userexit
>
>The userexit file only has this data in it:
>
>PO_NUMBER=123456
>
>I want to use the value of the PO_NUMBER in %2 in the batch file below:
>
>c:\edisendmail.exe -r ryan.johnson@... -s "PO %2 Received" -t "PO %2 Received"
>
>
>So the subject of my email would read:
>
>"PO 123456 Received"
>
>How can I have the batch file get the valued after "PO_NUMBER=" so it can be used in my email string?

This is one way:



@echo off
set /p var=<"C:\Edi\Prod\xlate\i\52122\userexit"
for /f "tokens=2 delims==" %%a in ("%var%") do set var=%%a
c:\edisendmail.exe -r r@... -s "PO %var% Received" -t "PO %var% Received"


Re: Read File and Use in Batch

by Ryan Johnson-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Sweet!  I got it to work.  I appreciate your help!




Re: Read File and Use in Batch

by Raagu :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

use this

key=PO_NUMBER
for /f "tokens=1-2 delims==" %%a in (C:\Edi\Prod\xlate\i\52122\userexit) do (
        if %%a equ !key! (

                c:\edisendmail.exe -r ryan.johnson@email.com -s "PO %%b Received" -t "PO %%b Received"
        )

)





Ryan Johnson-4 wrote:
I want to have a batch file open a file that I am passing to it as %1, read the data inside that file and use that later in the batch file.

At the command prompt I am typing this:

c:\>email_po.bat C:\Edi\Prod\xlate\i\52122\userexit

The userexit file only has this data in it:

PO_NUMBER=123456

I want to use the value of the PO_NUMBER in %2 in the batch file below:

c:\edisendmail.exe -r ryan.johnson@email.com -s "PO %2 Received" -t "PO %2 Received"


So the subject of my email would read:

"PO 123456 Received"

How can I have the batch file get the valued after "PO_NUMBER=" so it can be used in my email string?

Thanks,

Ryan Johnson