我正在尝试编写一个批处理脚本,它执行以下操作:
我已成功测试了以下代码。由于某些原因,我改变了价值' 1006000'其他一些价值观,如&00; 00000001'等等,脚本不起作用。
@ECHO OFF
for /l %%x in (1006000,1,1007000) do (
echo %%x
echo %%x>>C:\apache-jmeter-2.11\script\testdata1\ORDER_ID5.csv
echo %%x>>C:\apache-jmeter-2.11\script\ASAP\testdata2\ORDER_ID5.csv
echo %%x>>C:\apache-jmeter-2.11\script\ASAP\testdata3\ORDER_ID5.csv
echo %%x>>C:\apache-jmeter-2.11\script\ASAP\testdata4\ORDER_ID5.csv
echo %%x>>C:\apache-jmeter-2.11\script\ASAP\testdata5\ORDER_ID5.csv
echo %%x>>C:\apache-jmeter-2.11\script\ASAP\testdata6\ORDER_ID5.csv
echo %%x>>C:\apache-jmeter-2.11\script\ASAP\testdata7\ORDER_ID5.csv
echo %%x>>C:\apache-jmeter-2.11\script\ASAP\testdata8\ORDER_ID5.csv
)
因此,我正在尝试制作一个更灵活的脚本来生成CSV文件,CSV文件名显示批处理脚本生成的总记录。
@ECHO OFF
set startCounter = 1000000
set endCounter = 1050000
set totalRecords = %endCounter%-%startCounter%
set name = NewDataGen_%startCounter%_to_%endCounter%_%totalRecords%.csv
for /l %%x in (%startCounter%,1,%endCounter%) do (
echo %%x
echo %%x>>%name%
)
感谢您的帮助!
答案 0 :(得分:1)
您的问题很容易解决且性质一致。
set startCounter = 1000000
set endCounter = 1050000
作为例子。
set "var=value"
语法可确保批处理行上的任何尾随空格不包含在分配给var
的值中。
批处理对SET
语句中的空格敏感。 SET FLAG = N
将名为“FLAG Space ”的变量设置为值“ Space N”
但 set/a
语法不太特别,必须用于计算。 仅适用于整数值。
set startCounter=1000000
会愉快地工作,如果就行没有尾随空格
set /a startCounter=1000000
无论尾随空格如何,都会愉快地工作
set /a startCounter = 1000000
无论尾随空格如何,也会愉快地工作
set /a totalRecords = %endCounter%-%startCounter%
set /a totalRecords=%endCounter%-%startCounter%
set /a totalRecords = endCounter-startCounter
set /a totalRecords=endCounter-startCounter
(和其他结构)将全部计算totalrecords
(案例在批次中基本上无关。)/a
表示'算术模式中的过程'。
(第二种格式的个人偏好.YMMV)
答案 1 :(得分:0)
好了,已经知道了。脚本如下。非常感谢Magoo!
@ECHO OFF
set /a startCounter=1000000
set /a endCounter=1000100
set /a totalRecords=%endCounter%-%startCounter%
set name=NewDataGen_%startCounter%_%endCounter%_%totalRecords%.csv
for /l %%x in (%startCounter%,1,%endCounter%) do (
echo %%x
echo %%x>>%name%
)