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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.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 如何使用命令提示符添加一行文本并保存?_Batch File_Cmd - Fatal编程技术网

Batch file 如何使用命令提示符添加一行文本并保存?

Batch file 如何使用命令提示符添加一行文本并保存?,batch-file,cmd,Batch File,Cmd,我正在寻找使用CMD在文本文件中添加一行的方法 以下是原始文件 我想补充一点 “updateLocations”:“false”在该行中 结果 使用python脚本完成可以从命令行调用的任务 #!/usr/bin/env python import os, sys import json if len(sys.argv) != 2: print('invalid input arguments.') print('python3 insert_update_locations

我正在寻找使用CMD在文本文件中添加一行的方法

以下是原始文件

我想补充一点 “updateLocations”:“false”在该行中

结果


使用python脚本完成可以从命令行调用的任务

#!/usr/bin/env python

import os, sys
import json

if len(sys.argv) != 2:
    print('invalid input arguments.')
    print('python3 insert_update_locations_false.py [file_name]')
    exit()

file_name = sys.argv[1]

def main():
    print_job = read_file_in()
    print_job['updateLocations'] = False
    rewrite_file(print_job)


def read_file_in():
    with open(file_name, 'r') as f:
        jsonObj = json.load(f)
        return jsonObj


def rewrite_file(jsonObj):
    with open(file_name, 'w') as f:
        json.dump(jsonObj, f)


main()
然后可以从命令行调用它,如下所示:

python3 insert_update_locations_false.py job1.txt

这不是
add
update
操作吗?如果您在OSX或Linux上,您可以使用nano文本编辑器。我假设通过CMD,您指的是windows命令行。
#!/usr/bin/env python

import os, sys
import json

if len(sys.argv) != 2:
    print('invalid input arguments.')
    print('python3 insert_update_locations_false.py [file_name]')
    exit()

file_name = sys.argv[1]

def main():
    print_job = read_file_in()
    print_job['updateLocations'] = False
    rewrite_file(print_job)


def read_file_in():
    with open(file_name, 'r') as f:
        jsonObj = json.load(f)
        return jsonObj


def rewrite_file(jsonObj):
    with open(file_name, 'w') as f:
        json.dump(jsonObj, f)


main()
python3 insert_update_locations_false.py job1.txt