0

I want it so when I click on a batch file, It copies a LOT of stuff into a batch file, I tried this using the >> method, ( echo example>>example.txt ) and it only copies half of what I want it to copy, I have a lot of lines so I was wondering if there's a maximum of lines to copy and if there isn't why it isn't copying all of the stuff I want it to copy? (I want it to copy around 150 lines) EDIT: This is what I am trying to do:

SET FILECONTENTS=1.) In the url of the item you want to use the buy button on, Put Javascript:startbuy();^  
 2.) Inspect element on buy button.^  
 3.) Put the code at the bottom in it.^  
 4.) You now no longer need to refresh once the item goes onsale.^  
 <input type="submit" class="newPurchaseButton" value=""^  
ECHO %FILECONTENTS%>>testingfile.txt

So far it doesn't work.

jeb
  • 78,592
  • 17
  • 171
  • 225
  • Welcome to StackOverflow. What "stuff" is it supposed to copy? (In order to "copy", there has to be a "source" to copy from, and a "destination" to copy to - you've only provided half of that equation.) You need to edit your question to provide more details, and **post the code** that you're using that isn't working the way you'd expect. It would also help if you mentioned what a "batch file" is, since you've mentioned no language in your question. (I'd guess it's Windows batch, but you really need to state that for us if you want help.) – Ken White Sep 05 '12 at 23:13

2 Answers2

1

Most people do this the wrong way by having a hundred echo statements in the script, one per line, but there is a better way. The best way to do this is:

@echo off
setlocal EnableDelayedExpansion
set "LA=^<"
set "RA=^>"
:: 2 blank lines required below set NLM !
set NLM=^


set NL=^^^%NLM%%NLM%^%NLM%%NLM%

SET FILECONTENTS=^
 1.) In the url of use the buy button on, Put Javascript:startbuy();!NL!^
 2.) Inspect element on buy button.!NL!^
 3.) Exclamation^^! Put the code at the bottom in it.!NL!^
 4.) You now no longer need to refresh once the item goes onsale.!NL!^
 !LA!input type=^"submit^" class=^"newPurchaseButton^" value=^"^"!RA!

ECHO %FILECONTENTS%
ECHO %FILECONTENTS%>>test.txt     
pause
djangofan
  • 28,471
  • 61
  • 196
  • 289
1

Your code fails, as you try to use <> characters, but these are special charaters for batch (they are reserved for redirections).

But you can escape them and additionaly you should use delayed expansion for the echo command to avoid the same problem there.

setlocal EnableDelayedExpansion
SET FILECONTENTS=^
 1.) In the url of the item you want to use the buy button on, Put Javascript:startbuy();^
 2.) Inspect element on buy button.^
 3.) Put the code at the bottom in it.^
 4.) You now no longer need to refresh once the item goes onsale.^
 ^<input type="submit" class="newPurchaseButton" value=""^>

>>testingfile.txt ECHO !FILECONTENTS!

EDIT: Alternative way

If you also want to create linefeeds you could use simple echo statements in a block

(
  echo 1.^) In the url of the item you want to use the buy button on, Put Javascript:startbuy(^);
  echo 2.^) Inspect element on buy button.
  echo 3.^) Put the code at the bottom in it.
  echo 4.^) You now no longer need to refresh once the item goes onsale.
  echo ^<input type="submit" class="newPurchaseButton" value=""^>
) > testingfile.txt

For more solutions you could read SO:Splitting Doublequoted Line Into Multiple Lines in Windows Batch

Community
  • 1
  • 1
jeb
  • 78,592
  • 17
  • 171
  • 225
  • This code, which was a copy of my original answer from Sept 6th, does not work. I fixed it and edited my comment to show a completely working code snippet. – djangofan Sep 10 '12 at 04:08
  • The code works, as I made two important changes to your sample, the special characters are escaped and I echo the content with delayed expansion – jeb Sep 10 '12 at 07:44
  • I disagree. I just tried your code snippet (made Sept 9th) again and it fails. – djangofan Sep 10 '12 at 16:30
  • I would assume you get the same problem I do where the line feeds are not written to your file. In fact, you didn't specify any line feeds but it seems that is what the user intended. Also, you can't see it in your code yet, but there is a problem using left redirect with line feeds in the string, even though you think you're escaping properly. – djangofan Sep 10 '12 at 18:04
  • 1
    @djangofan No, it's not a problem, as the use of !FILECONTENTS! is safe against any content, as opposed to the percent expansion – jeb Sep 13 '12 at 06:49
  • Woah! Nice trick with the parenthesis. I didn't know that. It's actually better than my solution since it doesn't leave a blank space at the beginning of lines. Amazing find. Thanks. – djangofan Sep 14 '12 at 00:12