Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.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 对子流程的调用仅适用于PyCharm调试器_Python_Python 2.7_Grep_Subprocess_Pycharm - Fatal编程技术网

Python 对子流程的调用仅适用于PyCharm调试器

Python 对子流程的调用仅适用于PyCharm调试器,python,python-2.7,grep,subprocess,pycharm,Python,Python 2.7,Grep,Subprocess,Pycharm,我制作了一个Python脚本,其中一行通过子流程调用grep: master_start_time = subprocess.check_output(["grep", "-a", '"Time"', master_wav]).strip()[-23:] 当我使用Python解释器(v.2.7.12)运行它时,无论是从PyCharm执行还是通过远程shell执行(因为脚本和数据驻留在运行Ubuntu 16.04.1的远程机器上),都会持续出现以下错误: 但是,一旦我通过远程PyCharm调试器

我制作了一个Python脚本,其中一行通过
子流程调用
grep

master_start_time = subprocess.check_output(["grep", "-a", '"Time"', master_wav]).strip()[-23:]
当我使用Python解释器(v.2.7.12)运行它时,无论是从PyCharm执行还是通过远程shell执行(因为脚本和数据驻留在运行Ubuntu 16.04.1的远程机器上),都会持续出现以下错误:

但是,一旦我通过远程PyCharm调试器运行脚本,一切都会顺利运行

调试时,以下几行首先出现在PyCharm控制台中。他们应该总结调试配置

ssh://{user}@{server}:{port}{path to interpreter} -u {path to PyCharm debugger} --multiproc --qt-support --client '0.0.0.0' --port 35567 --file {path to script}
pydev debugger: process 18838 is connecting

有人知道如何防止出现这种情况吗?

结果表明,必须做的是删除子流程调用中
Time
一词周围的双引号

master_start_time = subprocess.check_output(["grep", "-a", 'Time', master_wav]).strip()[-23:]

我有一个类似的问题和类似的解决方案。在我的例子中,我在子流程中调用Python(以便运行不同版本的Python)。我在第三个参数中有一组额外的双引号,这是不必要的。我认为这里发生的事情是PyCharm,当配置为将调试器附加到子流程时,实际上为您修复了这个问题(可能是偶然的)。显然,如果不是在调试模式下运行,则不会发生这种情况。
master_start_time = subprocess.check_output(["grep", "-a", 'Time', master_wav]).strip()[-23:]