问题写入Fortran和C程序之间的管道 [英] Problem writing to a pipe between Fortran and C programs

查看:544
本文介绍了问题写入Fortran和C程序之间的管道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有别人这因此从标准输入读了一些东西,然后做一些计算并输出结果Fortran语言编写的程序。我想要做的就是从其他程序,由我用C写的运行与不同的输入数据多次。要做到这一点,我用的popen

I have a program written in Fortran by someone else which consequently reads a few things from the standard input and then does some calculations and outputs the result. What I want to do is to run it many times with different input data from another program, written in C by me. To do this I use popen:

  FILE *pipe = popen(".\\program.exe", "wt");
  if (!pipe) {
    exit(1);
  }

  fprintf(pipe, "%d\n", thing1);
  fprintf(pipe, "%d\n", thing2);
  ...

  pclose(pipe);

的问题是,它不以这种方式工作。它的工作原理完全符合的Program.exe< input.txt的,但不是这个样子。它读取的第一件事,然后输出这个愚蠢的错误:IO-09系统文件错误 - 未知错误。当然,我不知道这意味着什么,因为我从来没有编程的Fortran。

The problem is that it doesn't work this way. It works perfectly with "program.exe < input.txt" but not this way. It reads the first thing and then outputs this stupid error: "IO-09 system file error - unknown error". Of course I have no idea what this means as I've never programmed Fortran.

我在做什么错了?

编辑:

不幸的是我有一个程序没有源$ C ​​$ C

Unfortunately I have no source code of that program

推荐答案

它看起来像它应该工作,不知道为什么它没有。你确定
的popen()可在Windows机器上?我依稀记得它
不是可用于某些Windows系统。你可以用它试试
简单的C程序,看看它是否的popen()或Fortran程序。

It looks like it should work, not sure why it doesn't. Are you sure popen() is available on your Windows machine? I vaguely recall it not being available for some Windows systems. You could try it with a simple C program and see if it's popen() or the Fortran program.

作为解决办法,则可以将数据写入到一个临时文件,然后
使用系统(\\\\的Program.exe&LT;临时文件)来调用Fortran程序。
是啊,这是一个杂牌组装电脑。

As a workaround, you could write your data to a temporary file, then use system(".\\program.exe < tempfile") to call the Fortran program. Yeah, it's a kludge.

这篇关于问题写入Fortran和C程序之间的管道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆