1

i'm new in batch programmation and it's been 8 hours i'm trying to figure how to resolve my problem. That's why i'm here, i'm sure I passed out of something ...

I have a command

@ECHO OFF
echo Demarre le %date:~0,8% a %time:~0,5% >> C:\TEMP\pointage.csv

which put in pointage.csv the date on PC start up (we will call it A)

I have another command

@Echo Off&SetLocal
For /F "UseBackQ Tokens=1-4" %%A In (
    `Powershell "$OS=GWmi Win32_OperatingSystem;$UP=(Get-Date)-"^
    "($OS.ConvertToDateTime($OS.LastBootUpTime));$DO='d='+$UP.Days+"^
    "' h='+$UP.Hours+' n='+$UP.Minutes;Echo $DO"`) Do (
    Set "%%A"&Set "%%B"&Set "%%C")
Echo Temps de fonctionnement: %d% jour, %h% heures, %n% minutes >> C:\TEMP\pointage.csv
Echo Eteint le %date:~0,8% a %time:~0,5% >> C:\TEMP\pointage.csv

which put in pointage.csv the date when PC is shutdown (call B) + the time that pass between launch and shutdown (call C)

The problem is :

A, B & C are located in A1 for A, A2 for B, A3 for C in my pointage.csv

I want to put :

  • Every A results on column A,

  • Every B results on column B,

  • Every C results on column C.

in my pointage.csv

How to do that ? I tried many things, for example creating 3 files.txt and put them A,B & C then trying to use for /F function. But I don't find anything which works a little bit.

Thank you for helping !

1 Answer 1

1

Ok I found the problem, it's really simple ...

echo "hello";"stack";"overflow" >> pointage.csv

Worked

Here is my all code :

@echo off
setlocal
for /f %%a in ('wmic os get lastbootuptime ^| find "."') do (
  set _datetime=%%a
  )
set _boottime=%_datetime:~6,2%-%_datetime:~4,2%-%_datetime:~0,4%%_datetime:~8,2%:%_datetime:~10,2%

For /F "UseBackQ Tokens=1-4" %%A In (
    `Powershell "$OS=GWmi Win32_OperatingSystem;$UP=(Get-Date)-"^
    "($OS.ConvertToDateTime($OS.LastBootUpTime));$DO='d='+$UP.Days+"^
    "' h='+$UP.Hours+' n='+$UP.Minutes;Echo $DO"`) Do (
        Set "%%A"&Set "%%B"&Set "%%C"
)

Echo "%_boottime%";"%date:~0,8% %time:~0,5%";"%d% days, %h% hours, %n% minutes" >> C:\TEMP\pointage.csv
    
endlocal
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.