【问题标题】:open() - Fortran runtime error: File '' does not exist when exe ran with Python / Bottleopen() - Fortran 运行时错误:使用 Python/Bottle 运行 exe 时文件“不存在”
【发布时间】:2015-08-10 09:41:51
【问题描述】:

我有一个 Fortran exe 正在转移到 IaaS。 Fortan exe 在从控制台(Windows)运行时运行良好,但是当我从 Bottle RESTserver(本地)调用 exe 时,文件路径不起作用,并且出现以下错误:

At line 79 of file MainCalculator.f90 (unit = 61, file = '└')
Fortran runtime error: File '' does not exist

这是我执行 Fortran 的 Python / Bottle 代码:

def model():
    curr_dir = os.path.dirname(os.path.realpath(__file__))
    exe = "Calculator.exe"
    path = os.path.join(curr_dir, 'bin', 'fortan_model', 'Debug', exe)
    a = subprocess.Popen(path, shell=False)
    a.wait()

这是在 Fortran 中引发错误的代码行:

open(UNIT=61, FILE=trim(adjustl(recipePath))//"Scenarios.txt")

其中,recipePath = '..\..\ourRecipes\OUR_recipes_082014\'(在另一个 .f90 文件中定义)

文件路径似乎被报告为 ASCII 值(file = '└'),从命令行运行 exe 时不会发生这种情况。我认为它可能是相对路径,但它给出了与绝对路径相同的错误,但使用file = '≡f*☺└'

它还会创建一个文件名' Scenarios.txt'(前面有空格)。

编辑:Fortran .exe 读取输入 txt 文件。每行都分配给一个变量。这在命令行中按预期工作,但是当从 Bottle 执行时,它将输入文件解析为空白字符。我是否需要授予 Python 权限才能读取文件和/或打开内存中的输入文件?

【问题讨论】:

  • 尝试在open语句之前打印recipePath的内容。如果它包含一些奇怪的东西,请尝试找出原因。确保启用所有运行时检查和警告。 (-fcheck=all)。
  • 我无法在 Bottle 控制台窗口中打印 Fortran write(,) 语句,而我可以从 Bottle Python 脚本打印。 write(,) 语句在运行命令行时显示,而不是在通过 Bottle 脚本执行时显示
  • 然后将其写入文件,或使用调试器或其他任何方式。
  • 路径似乎是正确的,因为它保存在 String 变量中。问题似乎是字符编码问题

标签: python-2.7 fortran bottle


【解决方案1】:

我也遇到过类似的问题。

我通过减小输出文件名的大小解决了这个问题。

【讨论】:

    猜你喜欢
    • 2018-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-01
    • 1970-01-01
    • 2016-12-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多