Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file Windows批处理:序列号生成器到CSV文件_Batch File_Csv_Cmd - Fatal编程技术网

Batch file Windows批处理:序列号生成器到CSV文件

Batch file Windows批处理:序列号生成器到CSV文件,batch-file,csv,cmd,Batch File,Csv,Cmd,我正在尝试编写一个执行以下操作的批处理脚本: 读取插入到“startCounter”和“endCounter”变量中的参数 阶跃值为1的 将并发CSV文件写入多个目录。所有CSV文件都包含相同的数据,仅写入不同的目录 我已经成功地测试了以下代码。由于某些原因,当我将值“1006000”更改为诸如“00000001”等其他值时,脚本无法工作 @ECHO OFF for /l %%x in (1006000,1,1007000) do ( echo %%x echo %%x>

我正在尝试编写一个执行以下操作的批处理脚本:

  • 读取插入到“startCounter”和“endCounter”变量中的参数
  • 阶跃值为1的
  • 将并发CSV文件写入多个目录。所有CSV文件都包含相同的数据,仅写入不同的目录
  • 我已经成功地测试了以下代码。由于某些原因,当我将值“1006000”更改为诸如“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%
    )
    

    谢谢你的帮助

    你的问题很容易解决,而且本质上是一致的

    set startCounter = 1000000
    set endCounter = 1050000
    
    作为例子

    设置“var=value”
    语法确保批处理行上的任何尾随空格不包括在分配给
    var
    的值中

    批处理对
    SET
    语句中的空格敏感
    SET FLAG=N
    将名为“FLAGSpace”的变量的值设置为“SpaceN”

    但是
    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
    
    无论尾随空格是多少,都能很好地工作

    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)

    好,我已经知道了。脚本如下。非常感谢马古

    @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%
    )
    

    这是什么讨厌的东西?当然不是猛击!它看起来像是…Windows的东西,但是你说了好几次bash。对不起,这是Windows中的批处理脚本。那么,为什么代码会说
    #/顶部的bin/bash
    ?抱歉,已更正脚本,但仍无法生成任何输出。您能帮忙吗?非常重要的观察:批处理变量始终是字符串。如果它包含整数字符串,则可以作为整数操作。前导零使事情复杂化。前导零将值解释为八进制,因此
    0123
    123
    是不同的值。要获得前导零,请将100000000添加到值中,然后访问
    %var:~-n%
    ,这意味着“变量
    var
    的最后n个字符”。当然,这并不是全部内容。批处理带来更多乐趣!