K
K
KTG2019-03-16 12:25:16
cmd/bat
KTG, 2019-03-16 12:25:16

Why is writing to file not working?

@echo off
SetLocal EnableDelayedExpansion
for /F "delims=" %%i in (pack.id) do set pid=%%i
echo Last pack number: %pid%

  set /P pid_flag=Обновить номер пакета? [Y/N]:
  if /i %pid_flag% EQU y (
  
    set /A pid=%pid%+1 > pack.id	
    goto :end_pid_question
  ) 
  if /i %pid_flag% EQU n (
    set pid=%pid%
  ) ELSE (
    echo Try again...
    goto :pid_question
  )

Empty output to file. Even if there is no pack.id file, they are created, but nothing is written.
In fact, you need to take a number from there, do +1 and write it back to the file.
if I do: echo %pid% > pack.id
writes that the output of echo commands is disabled.
if I do: echo+%pid%>pack.idthen for some reason it writes 3 at the first start, and nothing more.
2. There is a second problem
set /P pid_flag=Обновить номер пакета? [Y/N]:
. If you do not enter characters and just press Enter, then a "syntax error" falls out.
And to process on absence of the data it is impossible.
Tried:
if not defined
if not exist
if not
Didn't take off (

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
res2001, 2019-03-16
@KTG

if I do: echo %pid% > pack.id
writes that the output of echo commands is disabled.

This happens when the %pid% variable is not defined (missing).
The error occurs on this line: when the %pid_flag% variable is not defined. Use this option: And it's not clear what kind of output to the file you are waiting for? If from this command: then do not wait - set does not print anything to the console if it was completed successfully.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question