Computing.Net > Forums > Disk Operating System > How to create a log file in 1 line

How to create a log file in 1 line

Reply to Message Icon

Original Message
Name: eso21
Date: February 22, 2003 at 22:53:16 Pacific
Subject: How to create a log file in 1 line
OS: 98/2000
CPU/Ram: 128
Comment:

Hi.. can anyone help me how to create a log file(in csv format) in one line of different information..

for example:

02/23/2003 14:00:00 DOS.txt 02/23/2003 14:02:55

where:
02/23/2003 14:00:00 - start date and time when DOS file was copied.
DOS - file that was copied
02/23/2003 14:02:55 - end date and time when DOS file was copied.

since if I used:
Now.exe >> C:\File.log
Echo DOS >> C:\File.Log
Now.exe >> C:\File.log

the output is:
02/23/2003 14:00:00
DOS.txt
02/23/2003 14:02:55

what I need is only in one line. Is it possible???

Thanks..


Report Offensive Message For Removal

Response Number 1
Name: Secret_Doom
Date: February 24, 2003 at 12:31:33 Pacific
Subject: How to create a log file in 1 line
Reply: (edit)

You don't need to use that external (3rd party, I guess) application for that. On windows 2000, do:

for /F "tokens=2" %%A in ("%DATE%") do set LOG=%%A
for /F "tokens=1 delims=." %%A in ("%TIME%") do set LOG=%LOG% %%A
:: Copying process goes here
set LOG=%LOG% DOS.TXT
for /F "tokens=2" %%A in ("%DATE%") do set LOG=%LOG% %%A
for /F "tokens=1 delims=." %%A in ("%TIME%") do set LOG=%LOG% %%A
echo %LOG%>> C:\File.log
set LOG=

You'll notice that some lines are repeated. In case you'll be using that log process several times on the script, you can avoid repeating the lines by creating a subroutine. Watch this sample:

@echo off
if "%1"=="GoTo" goto %2
echo Initializing LOG variable ...
set LOG=log begin
echo LOG=%LOG%
echo Adding time and date to the variable...
call %0 GoTo log
echo LOG=%LOG%
echo Adding additional text to the variable...
set LOG=%LOG% log end
echo LOG=%LOG%
set LOG=
goto eof
:log
if defined LOG set LOG=%LOG% %=%
for /F "tokens=2" %%A in ("%DATE%") do set LOG=%LOG%%%A
for /F "tokens=1 delims=." %%A in ("%TIME%") do set LOG=%LOG% %%A
goto eof
:eof

The output from that script is:

Initializing LOG variable ...
LOG=log begin
Adding time and date to the variable...
LOG=log begin 02/24/2003 17:24:48
Adding additional text to the variable...
LOG=log begin 02/24/2003 17:24:48 log end

When modifying the script, keep the two first lines, as well as the :log block (from ":log" to "goto eof") and the :eof label on the end of the file.

All that will only work on Windows 2000 and XP. It will fail under Win9x/DOS. Read my next post to see how to do it in Win9x.

-- Leonardo Pignataro - Secret_Doom --

secret_doom@hotmail.com
www.batch.hpg.com.br

_______________________________________________________________


Report Offensive Follow Up For Removal

Response Number 2
Name: Secret_Doom
Date: February 24, 2003 at 13:18:15 Pacific
Subject: How to create a log file in 1 line
Reply: (edit)

In Win9x/DOS, to add the date and time to the LOG variable, do this:

echo.exit|%comspec%/Kprompt set L=$D $T$_|FIND " " > %temp%.\T1.BAT
echo e11D D A 1A> %temp%.\T2.DAT
for %%? in (w q) do echo %%?>> %temp%.\T2.DAT
DEBUG %temp%.\T1.BAT < %temp%.\T2.DAT > nul
call %temp%.\T1.BAT
echo SET L=%%2 %%3> %temp%.\T1.BAT
call %temp%.\T1.BAT %L%
for %%? in (T1.BAT T2.DAT) do del %temp%.\%%?
set LOG=%LOG% %L%

The subroutine concept can also be applied to this method:

@echo off
if "%1"=="GoTo" goto %2

set LOG=log begin
call %0 GoTo log
set LOG=%LOG% log end
echo LOG=%LOG%
goto eof

:log
echo.exit|%comspec%/Kprompt set L=$D $T$_|FIND " " > %temp%.\T1.BAT
echo e11D D A 1A> %temp%.\T2.DAT
for %%? in (w q) do echo %%?>> %temp%.\T2.DAT
DEBUG %temp%.\T1.BAT < %temp%.\T2.DAT > nul
call %temp%.\T1.BAT
echo SET L=%%2 %%3> %temp%.\T1.BAT
call %temp%.\T1.BAT %L%
for %%? in (T1.BAT T2.DAT) do del %temp%.\%%?
if not "%LOG%"=="" set LOG=%L%
if "%LOG%"=="" set LOG=%LOG% %L%
set L=
goto eof

:eof

That's it.

-- Leonardo Pignataro - Secret_Doom --

secret_doom@hotmail.com
www.batch.hpg.com.br

________________________________________________________________


Report Offensive Follow Up For Removal

Response Number 3
Name: dtech10
Date: February 24, 2003 at 15:17:34 Pacific
Subject: How to create a log file in 1 line
Reply: (edit)

Hi eso21
The only way I see how to do this is by using an old dos program that I got from an old PC magazine, it's called Say.com and it allows you to echo text and control codes to a file or the screen.
It's syntax is Say.com "Hello" which would echo hello to the screen, but you can also do Say.com 65 66 67 13 10 which would echo "ABC" folowerd by a carriage return and a line feed.

What I'm geting at is you could create three environment variables and
echo them on one line in a batch file to your log file.
I take you or copying a file and want to know how long it takes to copy it, correct me if i'm wrong.
The batch file which I've called LogTxt.bat could if you wish be called
with two arguments, The first one the file and path to be copyied to and the second the destination. ie. Log.txt.bat c:\File1 d:\File2.
This could be your batch file.


rem [LogTxt.bat]

@echo off
rem echo the set command but with Ctrl Z at the end
say.com "@set Date1=" 26 > Log.bat

rem Log.bat now as "@set Date1=23/10/2003 14:23:55 ect
call now.exe >> Log.bat

rem set File=Filename (1st argument)
say.com "set File=" 26 >> Log.bat
echo %1 >> Log.bat

rem your copy command. Copy %1 to %2
copy %1 %2

rem set Date & Time again
say.com "set Date2=" 26 >> Log.bat
call now.exe >> Log.bat

rem execute the Log.bat file
rem You should now have 3 environment variables
rem Date1, File & Date2
call Log.bat

rem Now echo these to your Log.txt file
echo %date1% %file% %date2% >> Log.txt

rem Tidy up
del Log.bat
set Date1=
set File=
set Date2=

rem [End of LogTxt.bat]

PS: in windows 2000 you already have a %date% and %time%
environment variables, so you really don't need now.exe.
if these are'nt in the format you want let me know and I'll explain
how to modifly them.
If you can't find Say.com send me a email
Hope this helps Harry


Report Offensive Follow Up For Removal

Response Number 4
Name: Secret_Doom
Date: February 25, 2003 at 17:17:31 Pacific
Subject: How to create a log file in 1 line
Reply: (edit)

So, dtech10 provided a way to get your 3rd party application's outputs together in one line.

That would also be a way out, but the script would still depend on the 3rd party app now.exe, and with dtech10's suggestion, even another app is required.

Eso21, if you wish to make the process using that 3rd party app (now.exe) because it makes the source code simpler, I can provide a simple way of doing it but without needing one another app. Here we go:

@echo off
:: ASCII assembler by Laura Fairhead
echo XPYP[*'CC-\1P\QX,=P,APZ5O!PQ2O~5aaI~}Ksx> %temp%.\T1.COM
%temp%.\T1.COM SET D1=> %temp%.\T2.BAT
now.exe >> %temp%.\T2.BAT
:: Copy process goes here
%temp%.\T1.COM SET D2=>> %temp%.\T2.BAT
now.exe >> %temp%.\T2.BAT
call %temp%.\T2.BAT
echo %D1% DOS.TXT %D2%>> C:\File.log
for %%? in (1 2) do set D%%?=
for %%? in (T1.COM T2.BAT) do del %temp%.\%%?

The assembler program placed on the file T1.COM works just like the ECHO command, but it won't output a final CR/LF character. Look at the difference:

echo SET VAR=> temp.bat
now.exe>> temp.bat

The file temp.bat gets this:

SET VAR=
02/23/2003 14:00:00

Now, if we use the assembler program instead of the ECHO cmd, we get:

%temp%.\T1.COM SET VAR=> temp.bat
now.exe >> temp.bat

The file temp.bat gets this, instead:

SET VAR=02/23/2003 14:00:00

And then we can CALL the file temp.bat, sending the output from now.exe to a variable, to be used later.

Got the idea? But the good part is that T1.COM is created, used and deleted by the batch script, which means it's not a required application.

-- Leonardo Pignataro - Secret_Doom --

secret_doom@hotmail.com
www.batch.hpg.com.br

________________________________________________________________


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: How to create a log file in 1 line

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software