0

我想要它,所以当我点击一个批处理文件时,它将很多东西复制到一个批处理文件中,我使用 >> 方法尝试了这个,( echo example>>example.txt )它只复制了我想要的一半它要复制,我有很多行,所以我想知道是否有最多行要复制,如果没有,为什么它没有复制我想要复制的所有内容?(我希望它复制大约 150 行) 编辑:这就是我想要做的:

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

到目前为止,它不起作用。

4

2 回答 2

1

大多数人在脚本中有一百个 echo 语句,每行一个,这样做是错误的,但有更好的方法。最好的方法是:

@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
于 2012-09-06T00:08:23.323 回答
1

您的代码失败,因为您尝试使用<>字符,但这些是批处理的特殊字符(它们保留用于重定向)。

但是您可以逃避它们,并且您应该对 echo 命令使用延迟扩展以避免出现同样的问题。

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!

编辑:替代方式

如果您还想创建换行符,您可以在块中使用简单的 echo 语句

(
  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

有关更多解决方案,您可以阅读SO:Splitting Doublequoted Line Into Multiple Lines in Windows Batch

于 2012-09-07T20:43:49.997 回答