Problem with writing to file [solved]

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
dwngrt
Posts: 26
Joined: 07 Oct 2013 05:14
Location: The Netherlands

Problem with writing to file [solved]

#1 Post by dwngrt » 07 Oct 2013 05:22

Hello dear people!

I have a problem and i sort of need a solution quickly so i thought id ask it here :)
The problem is the following...

When i try to make a script that writes another script (both batch of course) i can't get the script to write
Pause>NUL to the other script. I need this for a TYPE auto-update script.

here is a little part of the script:

echo @echo off>>non-auto.bat
echo :main>>non-auto.bat
echo TYPE register.txt>>non-auto.bat
set 1=pause
set 2=
echo %1%%2%%3%>>non-auto.bat
echo goto main>>non-auto.bat
set update=start non-auto.bat
goto menu

sadly the result is this:
the main script will close, the other script whont start and this is what i find in the file:

@echo off
:main
TYPE register.txt

I tried things as variables to output this to the file, it doesn't work :/ not even when splitting the pause>NUL in several variables and i ran out of ideas...

anyone knows how to fix this problem?
Last edited by dwngrt on 14 Oct 2013 04:58, edited 1 time in total.

jeb
Expert
Posts: 1062
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: Problem with writing to file

#2 Post by jeb » 07 Oct 2013 05:35

Hi dwngrt,

I see two problems in your script.

You try to use variable names like 1 and 2, they are reserved for parameters, so you can't use them here.
The redirection character in your string needs an escape character so it becomes

Code: Select all

pause ^> NUL


Code: Select all

(
  echo @echo off
  echo :main
  echo TYPE register.txt
  echo pause ^>NUL
  echo goto main
) > non-auto.bat
start non-auto.bat
goto menu

dwngrt
Posts: 26
Joined: 07 Oct 2013 05:14
Location: The Netherlands

Re: Problem with writing to file

#3 Post by dwngrt » 07 Oct 2013 05:42

I thank you a lot jeb, you made my day! :D

Post Reply