Is it possible to call shell commands from a Fortran program?

In summary, the individual is seeking help with combining a Fortran program with MATLAB in Ubuntu 7.10 without using mex-functions or MATLAB engine functions. They are wondering if it is possible to do so by calling the shell, and are asking for guidance on how to do it. It is mentioned that using the gfortran compiler's "system" subroutine could work, but it is advised to avoid using this if possible due to compiler dependency.
  • #1
yo6781
1
0
Hello!

I'm new here and I was wondering if anyone could help me.

I've a program in fortran which I want to combine with Matlab, both working in Ubunt 7.10 but I don't want to use mex-functions or MATLAB engine functions because it could cause damage to the fortran program I'm using. I was wondering if it would be possible to do it with a calling to the shell. Does anybody know if it is possible and how could I do it??

Thank you
 
Technology news on Phys.org
  • #2
If you are using the gfortran compiler there is a subroutine called "system" http://gcc.gnu.org/onlinedocs/gfortran/SYSTEM.html" . But be aware about that this makes your code compiler dependent, so if it is possible you should avoid to use it.
 
Last edited by a moderator:
  • #3
for reaching out for help with your programming question. It is possible to call shell commands from a Fortran program, but the specific method may vary depending on your operating system and Fortran compiler. I would recommend researching the specific commands and syntax needed for your setup, as well as consulting with other Fortran and Matlab users for their experiences and suggestions. Additionally, testing and backing up your Fortran program before attempting to integrate it with Matlab is always a good idea to avoid any potential damage. Good luck with your project!
 

Related to Is it possible to call shell commands from a Fortran program?

1. How do I call a shell command in Fortran?

To call a shell command in Fortran, you can use the SYSTEM function. This function takes in a string argument that contains the command to be executed.

2. Can I pass arguments to the shell command when calling it in Fortran?

Yes, you can pass arguments to the shell command by including them in the string argument of the SYSTEM function. Make sure to properly format the arguments according to the shell command's syntax.

3. How do I capture the output of the shell command when calling it in Fortran?

To capture the output of the shell command, you can use the EXECUTE_COMMAND_LINE subroutine. This subroutine takes in a string argument for the command and an integer variable to store the command's exit status. The output of the command can be accessed through a file named command.out in the directory where the Fortran program is executed.

4. Is it possible to call a shell command asynchronously in Fortran?

Yes, it is possible to call a shell command asynchronously in Fortran using the EXECUTE_COMMAND_LINE_ASYNC subroutine. This subroutine is similar to EXECUTE_COMMAND_LINE, but it allows for multiple commands to be executed simultaneously.

5. Can I use environment variables when calling a shell command in Fortran?

Yes, you can use environment variables when calling a shell command in Fortran by including them in the string argument of the SYSTEM function. Make sure to properly format the variables according to the shell command's syntax.

Similar threads

  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
16
Views
2K
  • Programming and Computer Science
Replies
3
Views
2K
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
8
Views
2K
  • Programming and Computer Science
Replies
20
Views
3K
  • Programming and Computer Science
Replies
4
Views
1K
Replies
3
Views
791
  • Programming and Computer Science
Replies
16
Views
3K
  • Programming and Computer Science
Replies
33
Views
2K
Back
Top