简体   繁体   English

JQ 命令在 python 中不起作用

[英]JQ command not working in python

So I have a jq command that converts my json array into a json object.所以我有一个 jq 命令可以将我的 json 数组转换为一个 json 对象。 The command works normally in the windows terminal, but when I try to implement it into my python program i get this: jq: error:该命令在 Windows 终端中正常工作,但是当我尝试将它实现到我的 python 程序中时,我得到了这个: jq: 错误:

Could not open file >newfile.json: Invalid argument.

Here is my jq command which works and puts the transformed json into newfile.json:这是我的 jq 命令,它起作用并将转换后的 json 放入 newfile.json:

jq ".[]" data.txt >newfile.json

Here is my subprocess call in my python program:这是我在 python 程序中的子进程调用:

 subprocess.call('jq ".[]" data.txt >newfile.json', cwd=r'C:/Users/john/Desktop/swag', shell=True)

Open the output file yourself, and you won't need to rely on shell behavior (which is, obviously, not working in the present case) to do it for you.自己打开输出文件,您将不需要依赖 shell 行为(这显然在当前情况下不起作用)来为您完成。

subprocess.call(['jq', '.[]', 'data.txt'],
  cwd=r'C:/Users/john/Desktop/swag',
  stdout=open('C:/Users/john/Desktop/swag/newfile.json', 'w'))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM