Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/313.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
如何使用python os.system()将命令传递给mongoimport?upsertFields有空格_Python_Windows_Command Line_Mongoimport - Fatal编程技术网

如何使用python os.system()将命令传递给mongoimport?upsertFields有空格

如何使用python os.system()将命令传递给mongoimport?upsertFields有空格,python,windows,command-line,mongoimport,Python,Windows,Command Line,Mongoimport,我正在尝试将文件导入mongoDb Python 3.7、mongoimport、windows。 它可以完美地处理没有空间的字段 command = '"D:\\Program Files\\bin\\mongoimport.exe" -c _ --mode=merge --upsertFields="Current url",Title -d _ --file="D:\\folder\\folder\\temp.json" --jsonArray' os.system(command)

我正在尝试将文件导入mongoDb

Python 3.7、mongoimport、windows。 它可以完美地处理没有空间的字段

command = '"D:\\Program Files\\bin\\mongoimport.exe" -c _ --mode=merge --upsertFields="Current url",Title -d _  --file="D:\\folder\\folder\\temp.json" --jsonArray'
os.system(command)
结果: “D:\Program”未被识别为内部或外部命令

我认为这可能与逃跑有关,但我不知道确切的原因

我试过了

c2 = ["D:\\Program Files\\bin\\mongoimport.exe", '-c _ --mode=merge --upsertFields="Current url",Title -d _ --file="D:\\audiotorah\\audiotorah\\temp.json" --jsonArray']

import subprocess
subprocess.Popen(c2,stdin=subprocess.PIPE,stdout=subprocess.PIPE, bufsize =0)

但它永远不会停止。

为了避免转义,请在字符串之前附加一个
r
,使其成为原始字符串

使用操作系统:

import os

command = r'"D:\Program Files\bin\mongoimport.exe" -c _ --mode=merge --upsertFields="Current url",Title -d _ --file="D:\folder\folder\temp.json" --jsonArray'
os.system(command)
使用
subprocess.Popen

import subprocess, shlex

command = r'"D:\Program Files\bin\mongoimport.exe" -c _ --mode=merge --upsertFields="Current url",Title -d _ --file="D:\audiotorah\audiotorah\temp.json" --jsonArray'
subprocess.Popen(shlex.split(command), stdin=subprocess.PIPE, stdout=subprocess.PIPE)

它不起作用。”D:\Program'未被识别为内部或外部命令、可操作程序或批处理文件。-操作系统