make batch file that write another file [solved]

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

make batch file that write another file [solved]

#1 Post by abc0502 » 30 Oct 2011 05:28

Hi,
I'm trying to make a batch that write another file and then run it.
the problem is that it write the first line only and ignore the other two lines
I'm using ">>" to write the files

Code: Select all

@echo off
color F5
echo Set WshShell = CreateObject("WScript.Shell") >> "%homepath%\desktop\test.vbs"
echo WshShell.Run Chr(34) & "%systemdrive%\x.exe" & Chr(34), 0 >>"%homepath%\desktop\test.vbs"
echo Set WshShell = Nothing >> "%homepath%\desktop\test.vbs"
pause
call "%homepath%\desktop\test.vbs"
pause


the output file looks like that:

Code: Select all

Set WshShell = CreateObject("WScript.Shell")


any suggestions... help :?:
Last edited by abc0502 on 12 Mar 2012 00:34, edited 1 time in total.

Rileyh
Posts: 147
Joined: 01 Sep 2011 03:54
Location: Perth, Western Australia

Re: make batch file that write another file

#2 Post by Rileyh » 30 Oct 2011 05:40

Make the first occurrence of ">>" be ">". This means that it will make the file, instead of append to a file that does not exist. Then you can have the doubles:

Code: Select all

echo Set WshShell = CreateObject("WScript.Shell") >"%homepath%\desktop\test.vbs"
echo WshShell.Run Chr(34) & "%systemdrive%\x.exe" & Chr(34), 0 >>"%homepath%\desktop\test.vbs"
echo Set WshShell = Nothing >> "%homepath%\desktop\test.vbs"


By the way, this is a batch forum, not a vb forum. Please post batch file issues, not vb issues. That's why God invented the Visual Basic Forum, so that people don't have to post issues on batch forums.

Regards,
Rileyh

PS- No offence :D

alleypuppy
Posts: 82
Joined: 24 Apr 2011 19:20

Re: make batch file that write another file

#3 Post by alleypuppy » 30 Oct 2011 16:38

Rileyh wrote:Make the first occurrence of ">>" be ">". This means that it will make the file, instead of append to a file that does not exist.
It doesn't matter if the file doesn't exist, both ">" and ">>" will create the file if it doesn't exist.
Rileyh wrote:By the way, this is a batch forum, not a vb forum. Please post batch file issues, not vb issues. That's why God invented the Visual Basic Forum, so that people don't have to post issues on batch forums.
This is more of a batch file issue than a VBScript issue because the VBScript data is inside of a batch file

Post Reply