python调用并执行文件的语句问题


# 获取当前目录的文件路径
path = sys.path[0]
# 获取当前目录下所有文件的文件名
fileList = os.listdir()
# 遍历文件名
for filename in fileList:
    # 在遍历时,判断文件名中是否含有cellx_y字符,如果有则进行(File-merge.py)的调用,且只调用一次
    if re.findall(r'(\d_\d)', filename) and file_listdircount == 0:
        # 调用文件
        p = subprocess.Popen("python path" + file_name, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        (stdout, stderr) = p.communicate()
        # 调用计数
        file_listdircount = 1
        print('The file merge function has successfully executed!')
        break
# 如果没有,则输出提示并跳过调用执行下面的操作:
if file_listdircount == 0:
    print('There is no file name containing the cellx_y character in the current directory!')

代码中调用计数下方的的输出成功,但是调用失败了,调用的文件没有被执行,想请教一下,是路径出错?还是语句subprocess.Popen出错了?

我记得subprocess.Popen的第1个参数应该是列表。比如:

subprocess.Popen(['python', 'test.py', 'arg1', 'arg2'], stdout=sys.stdout, stdin=sys.stdin, stderr=sys.stderr)