Page 1 of 1

make batch file that write another file [solved]

Posted: 30 Oct 2011 05:28
by abc0502
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 :?:

Re: make batch file that write another file

Posted: 30 Oct 2011 05:40
by Rileyh
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

Re: make batch file that write another file

Posted: 30 Oct 2011 16:38
by alleypuppy
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