尝试执行子进程时没有此类文件或目录

2024-09-30 01:33:27 发布

您现在位置:Python中文网/ 问答频道 /正文

前言:我知道之前有人问过这个问题,但我无法从前面的答案中找到解决我的错误的方法。在

我只想调用diff来获得同一文件上两个不同命令的输出。在

 import os, sys
 from subprocess import check_call
 import shlex

 ourCompiler = 'espressoc';
 checkCompiler = 'espressocr';

 indir = 'Tests/Espresso/GoodTests';

 check_call(["pwd"]);

 for root, dirs, filenames in os.walk(indir):
     for f in filenames:
         if len(sys.argv) == 2 and sys.argv[1] == f:
             str1 = "<(./%s ./%s) " % (ourCompiler, os.path.join(root, f))
             str2 = "<(./%s ./%s) " % (checkCompiler, os.path.join(root, f))
             check_call(["diff", str1, str2])

为什么我收到以下错误?在

^{pr2}$

如果我从我的shell运行这个命令,它可以正常工作。在


Tags: inimport命令foroscheck错误sys
1条回答
网友
1楼 · 发布于 2024-09-30 01:33:27

diff正在抱怨它找不到具有奇怪名称<(./espressoc ./Tests/Espresso/GoodTests/Init.java)的文件,因为这是您输入的参数。在

^{}check_call是它的一个便利函数)是直接调用你给它的东西,没有一个shell来解释重定向或任何东西,除非你告诉它shell=True,然后它将通过/bin/sh(在POSIX上)调用该命令。使用前请注意security considerations。在

所以基本上:

subprocess.check_call(['diff', '<this', '<that'])` # strange files.
subprocess.check_call('diff <this <that', shell=True)` # /bin/sh does some redirection

如果您想要“纯粹”(可能比它值得付出更多的努力),我认为您可以将所有三个进程(diff、compiler1和compiler2)分处理,并自己处理管道。在关闭stdin之前,diff是否等待2个EOF或其他什么?不确定它是如何处理双输入重定向的,就像你的行。。。在

相关问题 更多 >

    热门问题