Linux中的Python子进程在文件存在时找不到文件

艾米

这个错误使我发疯。我的脚本输出错误:

>>>Run shell cmd "grep -vw ^# *.blastn | awk $1 != $2 > *matchfile*"
grep: /projects/percid100_2/blastn.outfile: No such file or directory
2

我检查了文件,它肯定在那里。

ll /projects/percid100_2/blastn.outfile
-rw-r--r-- 1  users 42633 Apr 17 12:34 /projects/percid100_2/blastn.outfile

上一个功能:

def run_blastn(outdir, outfile):
    """Run blastn under given percent identity """
    print ">>> Run blastn"
    blastnlog = os.path.join(outdir, 'blastn_db_log')
    # make database and run blastn 
    ref = Popen(['cmd1', '-logfile', blastnlog])
    ref.communicate()
    blastn = Popen(['cmd2', '-out', outfile], stderr=PIPE)

发生功能错误:

def filter_query(infile, matchfile):
    """Filter out self to self hit and no hit"""
    print ">>> Filter query self to self hit and no hit"
    print('>>> Run shell cmd "grep -vw ^# *.blastn | awk $1 != $2 > *matchfile*"')
    grep = Popen(['grep', '-vw', '^#', infile], stdout=PIPE)
    awk = Popen(['awk', '$1 != $2'], stdin=grep.stdout, stdout=PIPE)
    output = awk.communicate()[0]
    grep.communicate()
    if grep.returncode != 0:
        print grep.returncode
        sys.exit()

    with open(matchfile, 'wb') as ofile:
        print 'Write to file %s' % matchfile
        ofile.write(output)

主功能:

def main():
    parser = get_parser()
    args = parser.parse_args()
    if not os.path.exists(args.outdir):
        os.makedirs(args.outdir)
    outdir = os.path.abspath(args.outdir)

    bloutfile = 'blastn.outfile'
    path_bloutfile = os.path.join(outdir, bloutfile)

    # filter query seq outfile name 
    matchfile = 'match_file'
    path_matchfile = os.path.join(outdir, matchfile)

    # run blastn 
    run_blastn(outdir, path_bloutfile)
    # filter blastn output gain only matching information 
    filter_query(path_bloutfile, path_matchfile)

if __name__=='__main__':
    main()

函数输入之一infile是通过subprocess.Popen调用另一个程序从先前的函数生成的

我对这个问题的猜测是先前的命令已完成,并且此子进程调用无法识别先前函数的输出文件。我不知道我应该寻找什么解决方案。

如果我尝试多次运行脚本,该脚本最终将成功运行。

但是,这不行。

我尝试使用os.path.abspath(),但无法解决此问题。

阿巴内特

我愿意打赌,问题出在您描述的代码中,但是没有向我们展示,该代码运行“先前命令”,该命令生成grep正在寻找的文件

如果您通过创建来运行前一个命令Popen,但未wait在其上运行,则该命令仍将在后台运行。如果启动grep太快,则可能尚未创建该文件。所以你得到了错误。

然后,它需要几秒钟,你去看看在外壳的文件,到那个时候,它已经被创建。因此错误看起来令人困惑。

或者,如果您多次运行该程序,则最终可以正常工作-是因为您对计时感到幸运,或者是因为新运行找到了前一次运行遗留的文件。

该修复程序可能只是添加了missing other_command.communicate(),但没有看到其他代码,很难确定。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

找不到Python子进程文件

来自分类Dev

Python子进程nbtstat“找不到文件”

来自分类Dev

系统找不到指定的文件python子进程

来自分类Dev

系统找不到指定的文件python子进程

来自分类Dev

启动包含管道命令的子进程时找不到文件错误

来自分类Dev

python中的子进程:文件不存在

来自分类Dev

Hadoop流式处理子进程找不到文件

来自分类Dev

从 Linux EXTREME VPS 读取文件时找不到文件异常

来自分类Dev

在python子进程中找不到命令'command'

来自分类Dev

AppleScript:找不到存在的文件

来自分类Dev

即使文件存在并且在PATH中,Linux可执行文件也会失败并显示“找不到文件”

来自分类Dev

linux找不到这样的文件或目录,但是存在

来自分类Dev

虚拟主机:存在时找不到JavaScript文件

来自分类Dev

Python:在模块目录中找不到文件

来自分类Dev

找不到文件错误,但文件存在

来自分类Dev

php文件存在找不到文件

来自分类Dev

安装:找不到文件,但文件存在

来自分类Dev

在File上找不到文件。路径中存在空格

来自分类Dev

找不到Python模块,但存在于文件夹中

来自分类Dev

Python Pandas表示找不到列,但它们存在于csv文件中

来自分类Dev

在python中使用子过程导致找不到文件

来自分类Dev

Java在Linux中的.jar文件中找不到类

来自分类Dev

Java在Linux中的.jar文件中找不到类

来自分类Dev

导入文件时找不到文件

来自分类Dev

linux上的python在函数内找不到文件

来自分类Dev

Linux Ubuntu 14.00-找不到Apache2文件错误-文件存在

来自分类Dev

在python中使用子进程时如何处理文件名中的空格

来自分类Dev

在python中使用子进程时如何处理文件名中的空格

来自分类Dev

尝试在Eclipse中运行Python脚本时出现“ NameError:找不到模块maya的文件”

Related 相关文章

  1. 1

    找不到Python子进程文件

  2. 2

    Python子进程nbtstat“找不到文件”

  3. 3

    系统找不到指定的文件python子进程

  4. 4

    系统找不到指定的文件python子进程

  5. 5

    启动包含管道命令的子进程时找不到文件错误

  6. 6

    python中的子进程:文件不存在

  7. 7

    Hadoop流式处理子进程找不到文件

  8. 8

    从 Linux EXTREME VPS 读取文件时找不到文件异常

  9. 9

    在python子进程中找不到命令'command'

  10. 10

    AppleScript:找不到存在的文件

  11. 11

    即使文件存在并且在PATH中,Linux可执行文件也会失败并显示“找不到文件”

  12. 12

    linux找不到这样的文件或目录,但是存在

  13. 13

    虚拟主机:存在时找不到JavaScript文件

  14. 14

    Python:在模块目录中找不到文件

  15. 15

    找不到文件错误,但文件存在

  16. 16

    php文件存在找不到文件

  17. 17

    安装:找不到文件,但文件存在

  18. 18

    在File上找不到文件。路径中存在空格

  19. 19

    找不到Python模块,但存在于文件夹中

  20. 20

    Python Pandas表示找不到列,但它们存在于csv文件中

  21. 21

    在python中使用子过程导致找不到文件

  22. 22

    Java在Linux中的.jar文件中找不到类

  23. 23

    Java在Linux中的.jar文件中找不到类

  24. 24

    导入文件时找不到文件

  25. 25

    linux上的python在函数内找不到文件

  26. 26

    Linux Ubuntu 14.00-找不到Apache2文件错误-文件存在

  27. 27

    在python中使用子进程时如何处理文件名中的空格

  28. 28

    在python中使用子进程时如何处理文件名中的空格

  29. 29

    尝试在Eclipse中运行Python脚本时出现“ NameError:找不到模块maya的文件”

热门标签

归档