Append and delete bacth file needed

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
tisbris
Posts: 3
Joined: 05 Jun 2013 12:46

Append and delete bacth file needed

#1 Post by tisbris » 05 Jun 2013 13:01

Hello

I need some help creating a batch file...

I've an application that recieve data on COM1 and then create a txt file with the message recieved on COM1.
The application is then waiting for this txt file to be deleted before creating the next message (data is buffered inside the application).

I found this file watcher utility http://sourceforge.net/projects/fwutilities/?source=dlp and this utility can handle commands when ever a file is generated.

What I need is a command that will:
1. Read the text from the text file (message from COM1)
2. Append this text to an output.txt file
2a. Text should be added in a newline on each insert(append).
3. Only continue if text has been written to output.txt
4. Delete text file (COM1)


I have tried this:
TYPE c:\input.txt >> c:\output.txt
but I need help on how to make newline in output.txt and also how to secure that the insert has been handled before deleting the input file.

thank you

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Append and delete bacth file needed

#2 Post by foxidrive » 05 Jun 2013 14:08

This should monitor for the file, check every 10 seconds roughly, and append the text to the output file, and then add a newline and delete the input file.

Code: Select all

@echo off
:loop
if exist "c:\input.txt" (
echo found input file - processing...
TYPE "c:\input.txt" >> "c:\output.txt"
echo. >> "c:\output.txt"
del "c:\input.txt"
echo processing complete
echo.
)
ping -n 10 localhost >nul
goto :loop

tisbris
Posts: 3
Joined: 05 Jun 2013 12:46

Re: Append and delete bacth file needed

#3 Post by tisbris » 06 Jun 2013 02:54

thank you foxidrive.

This did what I asked for...

but, the application will not read the output fil.

Is there anyway that this could be sent to at tcp port on localhost instead of been written to the output file?

thx

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Append and delete bacth file needed

#4 Post by foxidrive » 06 Jun 2013 05:21

tisbris wrote:Is there anyway that this could be sent to at tcp port on localhost instead of been written to the output file?


Do you want the file uploaded to a HTTP server?

tisbris
Posts: 3
Joined: 05 Jun 2013 12:46

Re: Append and delete bacth file needed

#5 Post by tisbris » 06 Jun 2013 06:08

I need the raw text from the input file to be sent to an applikation (not http).

The only konfiguration i got inside this application is this:
[Channel 4]
Name=963
Host=127.0.0.1
Type=Visonik
Port=9999

This application is already recieving data from other systems directly - meaning without this input file. But this new system can only deliver text files.

The data form the old system can be seen on a telnet term - if that helps.

PS. We do not have the source code of this application :evil:


thx

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Append and delete bacth file needed

#6 Post by foxidrive » 06 Jun 2013 07:13

You might need to use a scriptable telnet to serve the data to the application, but that's a guess as we don't have access to test it.

There is a tool called TST which can be scripted - you can google on these details for it.

Telnet Scripting Tool v.1.0
by Albert Yale

Post Reply